Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run "runas ..."
How do I get the results and display in a MsgBox
Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run "runas ..."
How do I get the results and display in a MsgBox
You will want to use the WshShell object's Exec method instead of Run. Then simply read the command line's output from the standard streams. Try this one:
the third parameter must be true, and errorlevel will be return value, check if it is equal 0.
This is a modified version of Nilpo's answer that fixes the issue with
WshShell.Exec
being asynchronous. We do a busy-loop waiting until the shell's status is no longer running, and then we check the output. Change the command-line argument-n 1
to a higher value to makeping
take longer, and see that the script will wait longer until completion.(If anyone has a true asynchronous, event-based solution to the problem, then please let me know!)