Solved

Reading stdout from the Windows script host object

Posted on 2003-12-04
3
572 Views
Last Modified: 2010-05-01
Nothing is returning from the .read call ??
Any ideas on why this isn't working and what I should do to enable it??

Private Sub Command1_Click()

    Dim objwsh As New WshShell
    Dim sInput As String

    Set objWSHexec = objwsh.Exec("ipconfig")

    While Not objWSHexec.StdOut.AtEndOfStream
          sInput = sInput & objWSHexec.StdOut.Read(1)
         If InStr(sInput, "Press any key") <> 0 Then
            Exit Sub
         End If
    Wend
   
End Sub
0
Comment
Question by:mccainz2
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 200 total points
ID: 9876382
Try this

Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("%comspec% /c ipconfig.exe")

Do Until objExecObject.StdOut.AtEndOfStream
    strLine = objExecObject.StdOut.ReadLine()
    strIP = Instr(strLine,"Address")
    If strIP <> 0 Then
        Wscript.Echo strLine
    End If
Loop


From http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/scrguide/sas_wsh_pkoy.asp
0
 
LVL 5

Author Comment

by:mccainz2
ID: 9876500
Excellent Eddy! what is the purpose of comspec ????

Final code , only trivial modifications needed....

Private Sub Command2_Click()

    Dim Wscript As New WshShell
   
    Set objShell = New WshShell
    Set objExecObject = objShell.Exec("%comspec% /c ipconfig.exe")

    Do Until objExecObject.StdOut.AtEndOfStream
        strline = objExecObject.StdOut.ReadLine()
        Debug.Print strline
        strIP = InStr(strline, "Address")
    Loop

End Sub
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9876665
In WindowNT or high %comspec% returns cmd.exe
In Win95 or higher %comspec% returns command.exe
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question