在 VBScript 中获取命令行输出(不写入文件)
我正在使用 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
我的改编):
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
I'm using VBScript, and my goal is to be able to substitute a drive letter for a path of my choosing. I need the D drive, and if it's not available I need to check if it's already mapped to the right spot; then notify the user if it's not. I found this: http://technet.microsoft.com/en-us/library/ee156605.aspx and I'm trying to adapt their second example:
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
Then I'll probably search for the string that tells where the D drive is mapped. I've also tried objShell.Exec("subst")
, but I still don't get any output. Does anyone have any ideas on what I might be doing wrong? Or is there a better way to tell about drive mappings? Thanks,
213897
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的脚本无法运行,因为您输错了命令名称 - 它是
subst
,而不是substr
。Your script doesn't work because you've mistyped the command name - it's
subst
, notsubstr
.