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

Windows 在VBScript中获取命令行输出(不写入文件),windows,vbscript,subst,drive-mapping,Windows,Vbscript,Subst,Drive Mapping,我正在使用VBScript,我的目标是能够用驱动器号替换我选择的路径。我需要D驱动器,如果它不可用,我需要检查它是否已经映射到正确的位置;然后通知用户,如果它不是。我发现了这一点:我正在尝试改编他们的第二个例子: Set objShell = WScript.CreateObject("WScript.Shell") Set objExecObject = objShell.Exec("cmd /c ping -n 3 -w 1000 157.59.0.1") Do While Not objE

我正在使用VBScript,我的目标是能够用驱动器号替换我选择的路径。我需要D驱动器,如果它不可用,我需要检查它是否已经映射到正确的位置;然后通知用户,如果它不是。我发现了这一点:我正在尝试改编他们的第二个例子:

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
(我的改编):

然后我可能会搜索告诉D驱动器映射位置的字符串。我还尝试了
objShell.Exec(“subst”)
,但仍然没有得到任何输出。有人知道我可能做错了什么吗?还是有更好的方法来说明驱动器映射?谢谢


213897

您的脚本无法工作,因为您输入了错误的命令名-它是
subst
,而不是
substr

哇,这是几天来一直缺少的东西。。。谢谢你的帮助:)
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