VBScript gets results from Shell

Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run "runas ..."

How to get results and display in MsgBox

+3
source share
3 answers

You will want to use the Exec method of the WshShell object instead of Run. Then just read the command line output from standard threads. Try the following:

Const WshFinished = 1
Const WshFailed = 2
strCommand = "ping.exe 127.0.0.1"

Set WshShell = CreateObject("WScript.Shell")
Set WshShellExec = WshShell.Exec(strCommand)

Select Case WshShellExec.Status
   Case WshFinished
       strOutput = WshShellExec.StdOut.ReadAll
   Case WshFailed
       strOutput = WshShellExec.StdErr.ReadAll
End Select

WScript.StdOut.Write strOutput  'write results to the command line
WScript.Echo strOutput          'write results to default output
MsgBox strOutput                'write results in a message box
+16
source

Nilpo, , WshShell.Exec . , , . -n 1 , ping , , script .

( - , , , , !)

Option Explicit

Const WshRunning = 0
Const WshFinished = 1
Const WshFailed = 2

Dim shell : Set shell = CreateObject("WScript.Shell")
Dim exec : Set exec = shell.Exec("ping.exe 127.0.0.1 -n 1 -w 500")

While exec.Status = WshRunning
    WScript.Sleep 50
Wend

Dim output

If exec.Status = WshFailed Then
    output = exec.StdErr.ReadAll
Else
    output = exec.StdOut.ReadAll
End If

WScript.Echo output
0
var errorlevel = new ActiveXObject('WScript.Shell').Run(command, 0, true)

, errorlevel - , , 0.

-2

Source: https://habr.com/ru/post/1544036/


All Articles