Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBS Capture Command Output

Posted on 2009-05-15
3
Medium Priority
?
711 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

705 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