DOS Output in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • waqasmgl
    New Member
    • Nov 2007
    • 20

    #1

    DOS Output in VB

    Hi all,

    I have a problem that i m not getting how to solve that.

    I want to execute dos commands from VB6 and want to see the output in a textbox present in the form.

    For example i execute ipconfig command from vb6 then i want to see the output in a textbox.

    Now plz guide me how to execute dos commands from vb6 so that i can see the output in a textbox.

    Thanx
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    Code:
    Option Explicit
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    Private Sub Command1_Click()
    Dim INPUTTEXT As String
    Dim DOSSHELL As Variant
    Dim FNum As Integer
       On Error GoTo Error_Start
    '§ DOS command
       DOSSHELL = Shell("C:\windows\system32\cmd /C ipconfig > c:\ipconfig.txt ", 0)
    '§ wait 6 sec
       Sleep 6000
    '§ read the results
       FNum = FreeFile()
       On Error GoTo Error_Open
       Open "c:\ipconfig.txt" For Input As #FNum
          Do While Not EOF(FNum)
             Input #FNum, INPUTTEXT
             Text1.Text = Text1.Text & INPUTTEXT & vbCrLf
          Loop
       Close #FNum
    Exit Sub
    Error_Start:
       MsgBox ("There is an Error in executing the DOS command")
    Exit Sub
    Error_Open:
       MsgBox ("There is an Error in opening the file")
    End Sub

    Comment

    Working...