我是 vbscript 的初学者,我需要你的帮助,我的问题是如何从 cmd 获取变量并在 vbscript 中显示它,例如从 www.google.com 获取 ping 并在 vbscript 中的 msgbox 中显示它帮我编码:
dim cmd,x
set cmd = createobject("wscript.shell")
x= cmd.run("cmd /k ping www.google.com ",1,true)
获取该输出并稍后在 msgbox 中显示它,帮助我
我是 vbscript 的初学者,我需要你的帮助,我的问题是如何从 cmd 获取变量并在 vbscript 中显示它,例如从 www.google.com 获取 ping 并在 vbscript 中的 msgbox 中显示它帮我编码:
dim cmd,x
set cmd = createobject("wscript.shell")
x= cmd.run("cmd /k ping www.google.com ",1,true)
获取该输出并稍后在 msgbox 中显示它,帮助我
这是一个如何做到这一点的例子。检查的 ping 响应是荷兰语,但这对您的情况无关紧要。
Set objExec = CreateObject("WScript.Shell").exec("ping www.google.com")
With objExec
Do While .Status = 0
WScript.Sleep 10
Do While Not .StdOut.AtEndOfStream
WScript.Echo .StdOut.ReadLine
'Check the .StdErr to see if it is at the end of its
'stream. If not, call ReadLine on it
If Not .StdErr.AtEndOfStream Then
.StdErr.ReadLine
End If
Loop
Loop
End With
不过建议不要在 vbscript 中开始编写脚本,这是一条死胡同。选择一些现代脚本语言,如 Python,或者更适合初学者:Ruby。
确保使用 cscript 作为引擎而不是 wscript,执行以下命令将其设置为默认值。
wscript //H:Cscript
你的 vbscript 然后是一行
puts `ping www.google.com`