VBScript Capture StdOut from ShellExecute

Posted by Joe on Super User See other posts from Super User or by Joe
Published on 2012-09-24T14:37:42Z Indexed on 2012/09/24 15:40 UTC
Read the original article Hit count: 369

Filed under:
|
|

I am trying to run the following code snippet as part of a tool to gather and log some pertinent system diagnostics. The purpose of this snippet is to gather the result of running the command:

vssadmin list writers

The snippet is as follows:

'   Set WshShell = CreateObject("WScript.Shell")
'   WScript.Echo sCurPath & "\vsswritercheck.bat"
'   Set WshShellExec = WshShell.Exec("elevate.cmd cmd.exe /c " & sCurPath & "\vsswritercheck.bat")

Set oShell = CreateObject("Shell.Application")
oShell.ShellExecute "cmd.exe", sCurPath & "\vsswritercheck.bat", , "runas", 1
vsswriter = VSSWriterCheck

Select Case oShell.Status
    Case WshFinished
        strOutput = oShell.StdOut.ReadAll
    Case WshFailed
        strOutput = oShell.StdErr.ReadAll
End Select
WScript.Echo strOutPut
vsswriter = strOutPut

With the first code snippet (commented out) I can run the command and capture stdout from the batch file. In the second code snipped, I cannot capture stdout.

I need to be able to run the batch script with Elevated permissions, so I am looking for a compromise between the functionality of the two.

I cannot run the entire calling script in elevated mode due to restrictions from other pieces of functionality.

I am looking for any ideas on how to add this output to my log as I am running out of options that are within the scope of basic scripts.

© Super User or respective owner

Related posts about batch

Related posts about vbscript