Solved

VBS Capture Command Output

Posted on 2009-05-15
3
697 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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now