在VBScript中获取命令行输出(不写入文件)
问题描述:
我正在使用VBScript,我的目标是能够用我选择的路径替换驱动器号。我需要D盘,如果它不可用,我需要检查它是否已经映射到正确的位置;然后通知用户,如果不是。我发现这一点:http://technet.microsoft.com/en-us/library/ee156605.aspx,我努力适应他们的第二个例子:在VBScript中获取命令行输出(不写入文件)
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c ping -n 3 -w 1000 157.59.0.1")
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
If Instr(strText, "Reply") > 0 Then
Wscript.Echo "Reply received."
Exit Do
End If
Loop
(我的改编):
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c substr")
strText = ""
Do While Not objExecObject.StdOut.AtEndOfStream
strText = strText & objExecObject.StdOut.ReadLine()
Loop
Wscript.Echo strText
那么我可能会寻找它告知d驱动器中的字符串被映射。我也试过objShell.Exec("subst")
,但我仍然没有得到任何输出。有没有人有任何想法,我可能做错了什么?还是有更好的方法来讲述驱动器映射?谢谢,
答
您的脚本不工作,因为你已经输入了错误的命令名称 - 这是subst
,不substr
。
哇,这是相当多的东西失踪了几天...感谢您的帮助:) – 213897 2011-03-22 15:34:13