insert VBS variable within a single-quoted WMI query
- by jiaoziren
Hi all, I am really frustrated by the snippet below:
Dim objFSO, varSrc, varDest, varExt
Set objFSO = CreateObject("Scripting.FileSystemObject")
varSrc = WScript.Arguments(0)
varDest = WScript.Arguments(1)
varExt = WScript.Arguments(2)
If objFSO.FolderExists(varSrc) Then
WScript.Echo varSrc
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' AND " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""c:\\\\kk ""'")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
WScript.Echo objLatestEvent.TargetInstance.PartComponent
Loop
Else
WScript.Echo "Bazinga"
End If
I tried to replace c:\\kk with varSrc however it seems impossible for WSH to recognize it in WMI query - not to mention it was within a single quote!
I have tried chr(34) and it didn't work. Please help if possible. Much appreciated!