Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted
strcmd="cmd /c " & sCurPath & "\vsswritercheck.bat"
return = wshshell.run(strcmd , 0 , true)
if return=0 then
    blnSuccess = True
else
    blnSuccess = False
end if
share|improve this answer
    
It would be nice if you could provide a bit of context to go with the code :) –  Oliver Salzburg Sep 26 '12 at 15:27
    
I think that is almost what I need, but I need to capture StdOut from the script, not just if it was successful or not. –  Joe Oct 1 '12 at 13:05
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.