Solved

VBS Capture Command Output

Posted on 2009-05-15
3
701 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

867 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