smarttmelanie
04-28-2004, 08:46 AM
The script below will notify me if a file called 'Inspection' was created in C:\. However, it doesn't notify me if the file (Inspection) is created anywhere else except the root. Is there a way I can specify that it notify me if the file is created in all subfolders of C:\?
' Script that will detect the creation of a specific file in C:\test
Dim strQuery, FileToCheck
strQuery = "Select * From __InstanceCreationEvent Within 2 " _
& "Where TargetInstance ISA 'cim_DirectoryContainsFile' " _
& "AND TargetInstance.GroupComponent=" _
& "'Win32_Directory.Name=""c:\\\\""'"
FileToCheck = "Inspection"
' for remote, define a sComputerName variable and exchange the line
' above with this two ( in addition to the changes in the
' "GetObject("winmgmts:")" statement as well):
' & "AND TargetInstance.GroupComponent='\\\\" & sComputerName _
' & "\\root\\cimv2:Win32_Directory.Name=""c:\\\\test""'"
Set oEvents = GetObject("winmgmts:").ExecNotificationQuery (strQuery)
' now wait for events ...
Do While True ' loop indefinitely
Set oNTEvent = oEvents.NextEvent.TargetInstance ' retrieve event
if instrRev( ucase(oNTEvent.PartComponent), "\" & ucase(FileToCheck) ) = _
( len(oNTEvent.PartComponent) - len("\" & FileToCheck) ) then _
WScript.Echo "message " & oNTEvent.PartComponent
Loop
' Will give you an output on this format for each new file:
' \\\root\cimv2:CIM_DataFile.Name="c:\\test\\New.txt"
wscript.quit
Thanks for any feedback!!!
' Script that will detect the creation of a specific file in C:\test
Dim strQuery, FileToCheck
strQuery = "Select * From __InstanceCreationEvent Within 2 " _
& "Where TargetInstance ISA 'cim_DirectoryContainsFile' " _
& "AND TargetInstance.GroupComponent=" _
& "'Win32_Directory.Name=""c:\\\\""'"
FileToCheck = "Inspection"
' for remote, define a sComputerName variable and exchange the line
' above with this two ( in addition to the changes in the
' "GetObject("winmgmts:")" statement as well):
' & "AND TargetInstance.GroupComponent='\\\\" & sComputerName _
' & "\\root\\cimv2:Win32_Directory.Name=""c:\\\\test""'"
Set oEvents = GetObject("winmgmts:").ExecNotificationQuery (strQuery)
' now wait for events ...
Do While True ' loop indefinitely
Set oNTEvent = oEvents.NextEvent.TargetInstance ' retrieve event
if instrRev( ucase(oNTEvent.PartComponent), "\" & ucase(FileToCheck) ) = _
( len(oNTEvent.PartComponent) - len("\" & FileToCheck) ) then _
WScript.Echo "message " & oNTEvent.PartComponent
Loop
' Will give you an output on this format for each new file:
' \\\root\cimv2:CIM_DataFile.Name="c:\\test\\New.txt"
wscript.quit
Thanks for any feedback!!!