Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleExecute commands in a console window
Keywordsconsole window, DOS window
CategoriesWindows
 
Use the AllocConsole, GetStdHandle, WriteConsole, CloseHandle, and FreeConsole API functions.
 
Private Sub Form_Load()
Dim txt As String
Dim num_written As Long

    If AllocConsole() Then
        hConsole = GetStdHandle(STD_OUTPUT_HANDLE)
        If hConsole = 0 Then MsgBox "Couldn't allocate " & _
            "STDOUT"

        ' Present a warning.
        txt = "******************************************" _
            & vbCrLf & _
              "*   Warning: Do not close this window!   *" _
                  & vbCrLf & _
              "* Close the VB program's window instead. *" _
                  & vbCrLf & _
              "******************************************" _
                  & vbCrLf
        WriteConsole hConsole, txt, Len(txt), num_written, _
            vbNullString

        ' Make this form visible and on top.
        Me.Show
        SetFocus
    Else
        MsgBox "Couldn't allocate console"
    End If
End Sub

Private Sub Command1_Click()
Dim app_name As String
Dim txt As String
Dim num_written As Long

    app_name = App.Path
    If Right$(app_name, 1) <> "\" Then app_name = app_name _
        & "\"
    app_name = app_name & "test.bat"

    txt = "Ready to run" & vbCrLf
    WriteConsole hConsole, txt, Len(txt), num_written, _
        vbNullString
    Shell app_name
End Sub

Private Sub Form_Unload(Cancel As Integer)
    CloseHandle hConsole
    FreeConsole
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated