实现文件监控的最基本思想是:利用FindFirstChangeNotification 创建一个监控句柄,然后利用WaitForMultipleObjects来监视文件是否发生变化(循环判断文件的更新时间是否发生变化)。HANDLE FindFirstChangeNotification( LPCTSTR lpPathName, // pointer to name of directory to watch BOOL bWatchSubtree, // flag for monitoring directory or // directory tree DWORD dwNotifyFilter // filter conditions to watch for );DWORD WaitForMultipleObjects( DWORD nCount, // number of handles in the handle array CONST HANDLE *lpHandles, // pointer to the object-handle array BOOL fWaitAll, // wait flag DWORD dwMilliseconds // time-out interval in milliseconds );具体请参阅msdn
可以看看filemon
NetSessionGetInfoNetShareEnum
NetShareGetInfoNetFileEnum
NetFileGetInfo
创建一个监控句柄,然后利用WaitForMultipleObjects来监视文件是否发生变化(循环判断文件的更新时间是否发生变化)。HANDLE FindFirstChangeNotification(
LPCTSTR lpPathName, // pointer to name of directory to watch
BOOL bWatchSubtree, // flag for monitoring directory or
// directory tree
DWORD dwNotifyFilter // filter conditions to watch for
);DWORD WaitForMultipleObjects(
DWORD nCount, // number of handles in the handle array
CONST HANDLE *lpHandles, // pointer to the object-handle array
BOOL fWaitAll, // wait flag
DWORD dwMilliseconds // time-out interval in milliseconds
);具体请参阅msdn
>当然对我的文件进行复制时候,就自动弹出一个窗口让我确认了,对方才能进行复制我原来仔细看过 NetBlock 这个 shareware 的功能,我认为它就是定时刷新的方式使用 NetSessionEnum 和 NetFileEnum NetShareEnum 获得“实时”的共享和连接情况。对你说的情况其实就是当发现有新的“连接”或者访问的时候提示用户,并在用户要求断开连接的时候用
NetSessionDel 或 NetFileClose/NetFileClose2
来实现。
这里有很多例子
http://www.mvps.org/win32/index.html
看看左边那一帧,呵呵
的确是这样的,我发了以后才发现说的有点驴唇不对马嘴,不好意思了!
*^_^*