怎样用WMI来监视某个文件夹下的文件被打开的情况?WMI能实现吗?哪里有WMI的详细帮助文档啊?

解决方案 »

  1.   

    没有具体做过,不过可以肯定地说,可以实现,
    至于详细的帮助文章,VS.NET自带的MSDN中就有,而且是中文帮助,你直接用WMI索引就可以看到。
      

  2.   

    MSDN里面的WMI帮助嘛...中文的不够详细,还是去看MSDN.Platform SDK下面的英文帮助比较好...
    至于监视文件的话呢....
    NET本身有一个控件支持这样的功能,WMI有没有还得再找一下...
      

  3.   

    自带的有WMI介绍,但没有能实现我说的功能的帮助,我正在查微软网站上的e文的MSDN,费尽啊。
      

  4.   

    chaircat(chaircat) :.Net自带的FileSystemWatcher能够监视某个文件夹中文件的变化,比如最后访问时间。但是不是每次访问这个文件,他的最后访问时间都会变得,所以FileSystemWatcher就不行了。
      

  5.   

    同意楼上,FileSystemWatcher这个对象
      

  6.   

    FileSystemWatcher是做不到的,WMI也不行这个是杀毒软件常用的技术,有些软件用到了类似的技术,比如FileMon:
    http://www.sysinternals.com/Utilities/Filemon.htmlHow 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.
      

  7.   

    FileSystemWatcher 来监视运行时指定的目录。组件设置为监视 LastWrite 和 LastAccess 时间方面的更改,以及目录中文本文件的创建、删除或重命名。看楼主要实现怎样的功能了
      

  8.   

    http://www.thecodeproject.com/csharp/shellnotifications.asp
    看看这个
    用api
      

  9.   

    嘿嘿~~~~找到了~~~谁说WMI不行的??
    http://www.microsoft.com/technet/scriptcenter/scripts/storage/files/stfivb23.mspx
    看看这里吧~~~
      

  10.   

    监视文件修改当然可以了,不需要WMI,FileSystemWatcher就OK楼住需要监视“文件被打开的情况”
    打开了啥也不做也要监视
      

  11.   

    Sunmast(速马/COM+):不是监视文件修改,要监视文件打开,需要得到文件打开的次数。
      

  12.   

    回楼主和chaircat,WMI的文件系统监控毫无用处
    我们做过测试,如chaircat提供的地址的例子是没问题的,因为这个自建目录中一般文件比较少,而且又是针对一个特定的文件。
    但是对于较大的系统目录如c:\windows,甚至整个文件系统,这个监控毫无作用,表现为CPU占用率极高,而事件接收又毫无反应,估计是在扫描目录。
    所以,对于文件系统的监视,还是建议用FileSystemWatcher,但对于文件的打开操作,FileSystemWatcher好像也无能为力,WMI更是没法做到。
      

  13.   

    naclx():刚才测试了一下监视c:\windows\system32目录,果然CPU占用率很高,不过对文件的访问还是能监测到的。
      

  14.   

    文件的访问能够用WMI监测到,但是只能检测到一次打开的情况,如果文件已经打开还没有关闭,那再对这个文件的访问就监测不到了。
      

  15.   

    回naclx() 
    呵呵~~~~我找到这个例子一直都没测试~~~~~
    按你说的来看的话WMI的这个玩意就是一个循环扫描...
    看来要花比较小的代价实现这个问题可能只有去HOOK一下了~~~