| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 478 人关注过本帖
标题:文件夹监控
只看楼主 加入收藏
未名湖的云
Rank: 3Rank: 3
来 自:安徽
等 级:论坛游侠
帖 子:130
专家分:190
注 册:2012-10-11
结帖率:94.12%
收藏
已结贴  问题点数:2 回复次数:3 
文件夹监控
文件夹监控
搜索更多相关主题的帖子: 文件夹 监控 
2013-01-20 11:52
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
xp下感觉挺难

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

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-01-20 17:38
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分: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;
}

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-01-20 17:41
快速回复:文件夹监控
数据加载中...
 
   



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

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