VBScript 从 Shell 获取结果 [英] VBScript getting results from Shell

查看:53
本文介绍了VBScript 从 Shell 获取结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

如何获取结果并显示在 MsgBox 中

How do I get the results and display in a MsgBox

推荐答案

您需要使用 WshShell 对象的 Exec 方法而不是 Run.然后简单地从标准流中读取命令行的输出.试试这个:

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:

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

这篇关于VBScript 从 Shell 获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆