i'm trying to convert this function to wait notepad.exe to a generic wait function (that can wait for any process). I can't add a variable in the sQuery without breaking the syntax, is there any way to bypass the problem ?
Function wait()
Set svc=getobject("winmgmts:root\cimv2")
sQuery="select * from win32_process where name='notepad.exe'"
Set cproc=svc.execquery(sQuery)
iniproc=cproc.count
Do While iniproc = 1
wscript.sleep 5000
set svc=getobject("winmgmts:root\cimv2")
sQuery="select * from win32_process where name='notepad.exe'"
set cproc=svc.execquery(sQuery)
iniproc=cproc.count
Loop
Set cproc=nothing
Set svc=Nothing
End Function
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
Set wscr = CreateObject("Wscript.shell")
wscr.Run "notepad.exe"
wait()
MsgBox "done!"
I'm going crazy!!