怎么把CMD命令编写到VBS执行

2024-11-18 02:00:46
推荐回答(4个)
回答1:

用VBS不如直接用批处理。批处理不需要经过WScript.exe编译之后再执行。
直接把要运行的cmd命令写在记事本,每行一个,用回车换行。
之后把txt后缀改成bat或者cmd就可以了

回答2:

Set objShell = CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec ("%comspec% /c " & wscript.arguments(0))
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
loop
msgbox strText
保存为GetStdOut.vbs,在命令行里转到相应目录运行:
cscript.exe GetStdOut.vbs "ping 127.1"

看看,是不是出来了:
--------------------------------------------------------------------------------

Pinging 127.0.0.1 with 32 bytes of data:

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

回答3:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds:``

回答4:

好长时间没看了
不知道你是那一中