求助一个关于WMI的问题,高手帮帮忙啊

fokker 2005-12-06 10:07:10
怎样用WMI来监视某个文件夹下的文件被打开的情况?

WMI能实现吗?

哪里有WMI的详细帮助文档啊?
...全文
192 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
chaircat 2005-12-16
  • 打赏
  • 举报
回复
回naclx()
呵呵~~~~我找到这个例子一直都没测试~~~~~
按你说的来看的话WMI的这个玩意就是一个循环扫描...
看来要花比较小的代价实现这个问题可能只有去HOOK一下了~~~
fokker 2005-12-09
  • 打赏
  • 举报
回复
感谢大家,先结贴
fokker 2005-12-09
  • 打赏
  • 举报
回复
文件的访问能够用WMI监测到,但是只能检测到一次打开的情况,如果文件已经打开还没有关闭,那再对这个文件的访问就监测不到了。
fokker 2005-12-08
  • 打赏
  • 举报
回复
naclx():刚才测试了一下监视c:\windows\system32目录,果然CPU占用率很高,不过对文件的访问还是能监测到的。
naclx 2005-12-08
  • 打赏
  • 举报
回复
至于如何实现,个人觉得应该是有办法的,但是至少上述两个办法实现不了,楼主还要慢慢找了。
naclx 2005-12-08
  • 打赏
  • 举报
回复
回楼主和chaircat,WMI的文件系统监控毫无用处
我们做过测试,如chaircat提供的地址的例子是没问题的,因为这个自建目录中一般文件比较少,而且又是针对一个特定的文件。
但是对于较大的系统目录如c:\windows,甚至整个文件系统,这个监控毫无作用,表现为CPU占用率极高,而事件接收又毫无反应,估计是在扫描目录。
所以,对于文件系统的监视,还是建议用FileSystemWatcher,但对于文件的打开操作,FileSystemWatcher好像也无能为力,WMI更是没法做到。
fokker 2005-12-07
  • 打赏
  • 举报
回复
Sunmast(速马/COM+):不是监视文件修改,要监视文件打开,需要得到文件打开的次数。
fokker 2005-12-06
  • 打赏
  • 举报
回复
chaircat(chaircat) :.Net自带的FileSystemWatcher能够监视某个文件夹中文件的变化,比如最后访问时间。但是不是每次访问这个文件,他的最后访问时间都会变得,所以FileSystemWatcher就不行了。
fokker 2005-12-06
  • 打赏
  • 举报
回复
自带的有WMI介绍,但没有能实现我说的功能的帮助,我正在查微软网站上的e文的MSDN,费尽啊。
chaircat 2005-12-06
  • 打赏
  • 举报
回复
MSDN里面的WMI帮助嘛...中文的不够详细,还是去看MSDN.Platform SDK下面的英文帮助比较好...
至于监视文件的话呢....
NET本身有一个控件支持这样的功能,WMI有没有还得再找一下...
s5689412 2005-12-06
  • 打赏
  • 举报
回复
没有具体做过,不过可以肯定地说,可以实现,
至于详细的帮助文章,VS.NET自带的MSDN中就有,而且是中文帮助,你直接用WMI索引就可以看到。
速马 2005-12-06
  • 打赏
  • 举报
回复
监视文件修改当然可以了,不需要WMI,FileSystemWatcher就OK

楼住需要监视“文件被打开的情况”
打开了啥也不做也要监视
chaircat 2005-12-06
  • 打赏
  • 举报
回复
嘿嘿~~~~找到了~~~谁说WMI不行的??
http://www.microsoft.com/technet/scriptcenter/scripts/storage/files/stfivb23.mspx
看看这里吧~~~
lovefootball 2005-12-06
  • 打赏
  • 举报
回复
http://www.thecodeproject.com/csharp/shellnotifications.asp
看看这个
用api
timiil 2005-12-06
  • 打赏
  • 举报
回复
可能要下钩子比较方便
snowdyalan 2005-12-06
  • 打赏
  • 举报
回复
FileSystemWatcher 来监视运行时指定的目录。组件设置为监视 LastWrite 和 LastAccess 时间方面的更改,以及目录中文本文件的创建、删除或重命名。看楼主要实现怎样的功能了
速马 2005-12-06
  • 打赏
  • 举报
回复
FileSystemWatcher是做不到的,WMI也不行

这个是杀毒软件常用的技术,有些软件用到了类似的技术,比如FileMon:
http://www.sysinternals.com/Utilities/Filemon.html

How FileMon Works
For the Windows 9x driver, the heart of FileMon is in the virtual device driver, Filevxd.vxd. It is dynamically loaded, and in its initialization it installs a file system filter via the VxD service, IFSMGR_InstallFileSystemApiHook, to insert itself onto the call chain of all file system requests. On Windows NT the heart of FileMon is a file system driver that creates and attaches filter device objects to target file system device objects so that FileMon will see all IRPs and FastIO requests directed at drives. When FileMon sees an open, create or close call, it updates an internal hash table that serves as the mapping between internal file handles and file path names. Whenever it sees calls that are handle based, it looks up the handle in the hash table to obtain the full name for display. If a handle-based access references a file opened before FileMon started, FileMon will fail to find the mapping in its hash table and will simply present the handle's value instead.

Information on accesses is dumped into an ASCII buffer that is periodically copied up to the GUI for it to print in its listbox.
bitsbird 2005-12-06
  • 打赏
  • 举报
回复
同意楼上,FileSystemWatcher这个对象

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧