本帖最后由 lsq726 于 2010-1-3 23:01 编辑
在WMI教程中有个例子。:
文件监控的例子$strComputer = "."
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\cimv2")
$colMonitoredEvents = $objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceDeletionEvent WITHIN 1 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""c:\\\\1""'")
While 1
$objEventObject = $colMonitoredEvents.NextEvent()
Select
Case $objEventObject.Path_.Class()="__InstanceDeletionEvent"
ConsoleWrite ("A file was just deleted: " & $objEventObject.TargetInstance.PartComponent() & @CR)
EndSelect
WEnd
这段代码 只能对当前目录下删除文件进行监控。不能对其子目录的删除文件进行监控。
如果c:\1下有很多子目录
c:\1\1
c:\1\2
c:\1\33333
c:\1\555555555555555555555
c:\1\67
c:\1\21
c:\1\234
c:\1\5436457568
怎么可以让其 对所有的目录的子目录也能进行删除监控?
还请高手指点 |