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

38,720

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

Share:
38,720
213897
Author by

213897

Updated on March 23, 2020

Comments

  • 213897
    213897 over 4 years

    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