VBScript Capture StdOut from ShellExecute

batchvbscriptvss

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.

Best Answer

strcmd="cmd /c " & sCurPath & "\vsswritercheck.bat"
return = wshshell.run(strcmd , 0 , true)
if return=0 then
    blnSuccess = True
else
    blnSuccess = False
end if
Related Question