set ws = WScript.CreateObject("WScript.Shell")
cmd = "schtasks /Query | findstr /i My_Task"
retcode = ws.run(cmd,0,True)
I expect retcode = 0 when My_Task exists. The
same command actually worked when I ran it in
cmd.exe. Perhaps there is some oddity with
vbscript's handling of the pipe?
Would appreciate any suggestion.
/Why Tea
Pipes are supported by the command processor, so it needs to be
invokes ...
retcode = ws.run("%comspec% /c " & cmd,0,True)
Tom Lavedas
Thanks Tom. It works perfectly now.
Close.
As far as VBScript is concerned, the pipe character is just a text character
in a string being passed to the .Run method. The .Run method then gets the
system to execute the SCHTASKS.EXE program, which also knows nothing about
pipes.
If you want to execute a command that works when run with cmd.exe, you
generally have to run cmd.exe with something like:
> set ws = WScript.CreateObject("WScript.Shell")
> cmd = "cmd.exe /c schtasks.exe /Query | findstr /i My_Task"
> retcode = ws.run(cmd,0,True)
Alternately, it can be simpler to get the correct syntax by .Running a batch
file created to do precisely what you want.
/Al