acovich
05-19-2006, 06:28 AM
Sorry guys, this is driving me crazy.
I've written (borrowed/copied/made up) a script that will monitor a directory for new files being created, and it works fine. Now I would like to have an argument added which determines that directory at executing of cscript (so I can type cscript.exe monitor.vbs c:\scripts for instance). I can't get it to work.
Here's what I've tried:
strComputer = "."
fold = wscript.arguments.item(0)
foldr = replace(fold,"\","\\\\")
wscript.echo foldr
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name="& foldr & "'")
Do While TRUE
Set objEventObject = colMonitoredEvents.NextEvent()
Select Case objEventObject.Path_.Class
Case "__InstanceCreationEvent"
etc etc...
no matter how hard I try to massage the & "'Win32_Directory.Name="& foldr & "'") line, I always get either an unparsable or invalid query. It works fine with c:\\\\scripts (etc). Can anyone please help me out? Much appreciated!
Adrian
I've written (borrowed/copied/made up) a script that will monitor a directory for new files being created, and it works fine. Now I would like to have an argument added which determines that directory at executing of cscript (so I can type cscript.exe monitor.vbs c:\scripts for instance). I can't get it to work.
Here's what I've tried:
strComputer = "."
fold = wscript.arguments.item(0)
foldr = replace(fold,"\","\\\\")
wscript.echo foldr
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name="& foldr & "'")
Do While TRUE
Set objEventObject = colMonitoredEvents.NextEvent()
Select Case objEventObject.Path_.Class
Case "__InstanceCreationEvent"
etc etc...
no matter how hard I try to massage the & "'Win32_Directory.Name="& foldr & "'") line, I always get either an unparsable or invalid query. It works fine with c:\\\\scripts (etc). Can anyone please help me out? Much appreciated!
Adrian