开发者

Getting command line output in VBScript (without writing to files)

开发者 https://www.devze.com 2023-02-19 03:48 出处:网络
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 righ

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 I开发者_StackOverflow中文版nstr(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


Your script doesn't work because you've mistyped the command name - it's subst, not substr.

0

精彩评论

暂无评论...
验证码 换一张
取 消