2

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.

Joe
  • 173

2 Answers2

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

How about using them both?

Use that code you commented out, which works in non-elevated mode, and add an extra test where, if elevated rights are needed, the script will instead call itself using ShellExecute(), causing the subsequent call to Exec() to already have elevated rights and still capture stdout.

It's a bit wacky, but effortless.

Crafty
  • 1