在VBScript中获取命令行输出(无需写入文件)

6
我正在使用VBScript,我的目标是能够将我选择的路径替换为驱动器字母。我需要D盘,如果不可用,我需要检查它是否已映射到正确的位置;然后通知用户。我找到了这个:http://technet.microsoft.com/en-us/library/ee156605.aspx,我正在尝试适应他们的第二个示例:
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

(my adaptations):

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"),但是我仍然没有得到任何输出。 有人对我做错了什么有想法吗?或者有更好的方法来查找驱动器映射吗?谢谢。

213897

1个回答

5

您的脚本无法运行,因为您错误地输入了命令名称 - 它应该是subst,而不是substr


哇,这是几天来缺失的东西...谢谢你的帮助 :) - 213897

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接