Re:
WshShell.Run("C:\schtasks /query /s &arg")
(1) VBScript does not interpolate variables, you have to concatenate the content of arg
(properly):
WshShell.Run "C:\schtasks /query /s " & arg
(WRT @Ansgar's posting: I assume arg
holds the computer name (hopefully) optained by
arg=inputbox("Enter the computername")
and that your next line:
Set arg = Wscript.Arguments
was added by the copy-&-paste-goblin)
(2) You must not use param list () when calling a sub/not receiving a return value. So either use the above line or
iRet = WshShell.Run("C:\schtasks /query /s " & arg)
Re: display the result
As .Run
just executes the command and returns a status, the least cost/most gain method to get the output of schtasks
is .Exec
:
Option Explicit
Dim oWSH : Set oWSH = CreateObject("WScript.Shell")
Dim sCmd : sCmd = "schtasks /Query /S winxpsp3"
Dim sRes : sRes = oWSH.Exec(sCmd).Stdout.ReadAll()
WScript.Echo sRes
Use the docs to learn how to improve my demo snippet - a production ready version should do some error handling.
If you don't want to use .Exec
, see this answer for sample code that uses .Run
and re-direction to get the command's output.