VBS Capture Command Output

Hi Folks,

The attached code is in a loop where everytime it runs, strcomputername is changed - thus shutting down multiple machines in a target list.

The problem I am having is that strcapture is always an empty carriage return when written out to the logfile.  I know that if the machine shutdown is successful then the empty blank line returned is expected, but when i run the command against a machine name that doesn't exist, it should come back with an error like "The Network Path Was Not Found" or similar.

How can i get strCapture to capture the output correctly?
strCommand = "shutdown -s -m \\" & strcomputername & " -t 00 -f"
Set objScriptExec = objShell.Exec(strCommand)
strCapture = objScriptExec.StdOut.ReadAll
LogFile.WriteLine(strCapture)

Open in new window

LVL 8
Pearl_export_benAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
yehudahaConnect With a Mentor Commented:
try to change this line

strCommand = "shutdown -s -m \\" & strcomputername & " -t 00 -f"

to this

strCommand = "cmd /c shutdown -s -m \\" & strcomputername & " -t 00 -f"
0
 
bluntTonyCommented:
Try the below code.

You usually have to put in a loop to wait until the Exec has finished (Status = True), then read StdOut.
strCommand = "shutdown -s -m \\" & strcomputername & " -t 00 -f"
Set objScriptExec = objShell.Exec(strCommand)
Do Until objScriptExec.Status
   Wscript.Sleep 250
Loop
strCapture = objScriptExec.StdOut.ReadAll
LogFile.WriteLine(strCapture)

Open in new window

0
 
yehudahaCommented:
thanks
0
All Courses

From novice to tech pro — start learning today.