Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBS Capture Command Output

Posted on 2009-05-15
3
Medium Priority
?
713 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:Pearl_export_ben
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
yehudaha earned 2000 total points
ID: 24393872
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
 
LVL 27

Expert Comment

by:bluntTony
ID: 24395304
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
 
LVL 14

Expert Comment

by:yehudaha
ID: 24403841
thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question