标题:文件夹监控
只看楼主
未名湖的云
Rank: 3Rank: 3
来 自:安徽
等 级:论坛游侠
帖 子:130
专家分:190
注 册:2012-10-11
结帖率:94.12%
已结贴  问题点数:2 回复次数:3 
文件夹监控
文件夹监控
搜索更多相关主题的帖子: 文件夹 监控 
2013-01-20 11:52
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:0 
xp下感觉挺难

DO IT YOURSELF !
2013-01-20 12:56
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6809
专家分:42393
注 册:2010-12-16
得分:1 
不难,
简单点的直接注册一个消息就可以了,这样只能是监控,不能拦截和修改
复杂点 就挂钩api,挂钩api 就可以拦截 ,拒绝、或者修改等
再复杂点就写个驱动什么的了

我行我乐
我的博客:
http://blog.yuccn. net
2013-01-20 17:38
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6809
专家分:42393
注 册:2010-12-16
得分:1 
SHChangeNotifyRegister
SHChangeNotifyDeregister

查下这两个函数的用法就行了
下面的是以前写的,可以供你参考下:

void CDiskMonDlg::OnBnClickedOk()
{
    this->InitFunc();

    IDLSTRUCT ps;

    if (m_bStartMon == 0) {  
        SHGetSpecialFolderLocation(0, CSIDL_DRIVES, &g_pidlDesktop);
        if (g_pidlDesktop != NULL) {   
            memset(&ps, 0x00, sizeof(IDLSTRUCT));
            ps.pidl = g_pidlDesktop;
            ps.bWatchSubFolders = 1;

            m_bStartMon = g_SHChangeNotifyRegister((long)m_hWnd, SHCNF_TYPE | SHCNF_IDLIST, SHCNE_ALLEVENTS | SHCNE_INTERRUPT, WM_SHNOTIFY, 1, &ps);

            ::SetDlgItemText(m_hWnd, IDOK, L"停止");
        }   
    }
    else {   
        if (g_SHChangeNotifyDeregister(m_bStartMon)) {  
            m_bStartMon = 0;
            CoTaskMemFree(g_pidlDesktop);
            g_pidlDesktop = 0;
            ::SetDlgItemText(m_hWnd, IDOK, L"监控");
            memset(&m_LastNii, 0, sizeof(NOTIFY_ITEM_INFO));
        }   
    }
}


LRESULT CDiskMonDlg::OnNotifyReceipt(WPARAM wParam, LPARAM lParam)
{     
    WCHAR wzEvent[2048] = { 0 };
    WCHAR wzPath1[512] = { 0 };
    WCHAR wzPath2[512] = { 0 };

    SHNOTIFYSTRUCT *pidlItem = PSHNOTIFYSTRUCT(wParam);
    SHGetPathFromIDListW(pidlItem->dwItem1, wzPath1);
    SHGetPathFromIDListW(pidlItem->dwItem2, wzPath2);

    if (wzPath1[0] == L'\0' && wzPath1[1] == L'\0') {
        return 1;
    }

    if (m_LastNii.dwType == (DWORD)lParam &&
        wcscmp(wzPath1, m_LastNii.wzPath1) == 0 &&
        wcscmp(wzPath2, m_LastNii.wzPath2) == 0) {
            // 主要是防止重复的信息
            return 0;
    }
   
    switch(lParam)
    {
    case SHCNE_RENAMEITEM:
        swprintf_s(wzEvent, _countof(wzEvent), L"文件: %s 重命名为: %s。", wzPath1, wzPath2);
        break;
    case SHCNE_CREATE:   
        swprintf_s(wzEvent, _countof(wzEvent), L"新建文件:%s。", wzPath1);
        break;
    case SHCNE_DELETE:
        swprintf_s(wzEvent, _countof(wzEvent), L"删除文件:%s。", wzPath1);
        break;
    case SHCNE_MKDIR:  
        swprintf_s(wzEvent, _countof(wzEvent), L"新建文件夹:%s。", wzPath1);
        break;
    case SHCNE_RMDIR:     
        swprintf_s(wzEvent, _countof(wzEvent), L"删除文件夹:%s。", wzPath1);
        break;
    case SHCNE_MEDIAINSERTED:
        swprintf_s(wzEvent, _countof(wzEvent), L"%s 中插入可移动存储器。", wzPath1);
        break;
    case SHCNE_MEDIAREMOVED:  
        swprintf_s(wzEvent, _countof(wzEvent), L"%s 中移去可移动存储器。", wzPath1);
        break;
    case SHCNE_DRIVEREMOVED:   
        swprintf_s(wzEvent, _countof(wzEvent), L"移去驱动器: %s。", wzPath1);
        break;
    case SHCNE_DRIVEADD:      
        swprintf_s(wzEvent, _countof(wzEvent), L"添加驱动器: %s。", wzPath1);
        break;
    case SHCNE_NETSHARE:
        swprintf_s(wzEvent, _countof(wzEvent), L"改变文件夹 %s 的共享属性。", wzPath1);
        break;
    case SHCNE_UPDATEDIR:  
        swprintf_s(wzEvent, _countof(wzEvent), L"更新文件夹: %s。", wzPath1);
        break;
    case SHCNE_UPDATEITEM:        
        swprintf_s(wzEvent, _countof(wzEvent), L"修改了文件: %s。", wzPath1);
        break;
    case SHCNE_SERVERDISCONNECT:   
        swprintf_s(wzEvent, _countof(wzEvent), L"断开与服务器的连接: %s %s。", wzPath1, wzPath2);
        break;
    case SHCNE_DRIVEADDGUI:      
        swprintf_s(wzEvent, _countof(wzEvent), L"添加并显示驱动器: %s。", wzPath1);
        break;
    case SHCNE_RENAMEFOLDER:   
        swprintf_s(wzEvent, _countof(wzEvent), L"文件夹: %s 重命名为 %s。", wzPath1, wzPath2);
        break;
    default:   
        swprintf_s(wzEvent, _countof(wzEvent), L"其他操作。");
        break;
    }

    m_LastNii.dwType = (DWORD)lParam;
    wcscpy_s(m_LastNii.wzPath1, _countof(m_LastNii.wzPath1), wzPath1);
    wcscpy_s(m_LastNii.wzPath2, _countof(m_LastNii.wzPath1), wzPath2);


    SYSTEMTIME stTime = {0};
    ::GetLocalTime(&stTime);

    WCHAR wzTime[32] = { 0 };
    swprintf_s(wzTime, _countof(wzTime), L"%02d:%02d:%02d", stTime.wHour, stTime.wMinute, stTime.wSecond);

    m_pInfoList->InsertItem(0, wzTime);
    m_pInfoList->SetItemText(0, 1, wzEvent);   

    return 0;
}

我行我乐
我的博客:
http://blog.yuccn. net
2013-01-20 17:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-397130-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.510392 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved