This is a test script that I am trying to get to work before I
incorporate it into the real thing. I am trying to get the
__InstanceModificationEvent to cooperate. Creation & Deletion events
work great. I can't figure out what triggers the Modification event.
I just want it to tell me if a file has been modified. By that I mean
if there is a file in the C:\X directory and a newer version of the
file is copied on top of the existing one, I would think that the
Modification Event would be triggered. Am I wrong. Someone please
help.
NoSeconds = "2"
MonitoredFolder = "C:\X"
CorrectMonitoredFolder = Replace( MonitoredFolder, "\", "\\\\" )
strComputer = "."
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set objWMIService = GetObject( "winmgmts:" &_
"{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\cimv2" )
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN " & NoSeconds & "
WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""" & CorrectMonitoredFolder & """'" )
Do While True
Set objEventObject = colMonitoredEvents.NextEvent()
Select Case objEventObject.Path_.Class
Case "__InstanceCreationEvent"
WScript.Echo "Created"
Case "__InstanceModificationEvent"
WScript.Echo "Modified"
Case "__InstanceDeletionEvent"
WScript.Echo "Deleted"
End Select
Loop