Solved

Reading stdout from the Windows script host object

Posted on 2003-12-04
3
564 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now