Results 1 to 4 of 4

Thread: Closing a dos program windows after you ran it with Shell

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    51
    I used the command "shell" to open a DOS program and my problem is that once the DOS program is done, the windows stay open. I tried to hide the windows, but it will just stay loaded in memory but invisible.

    I'm pretty sure I could close it using the ID it return but I have no idea how to do it in VB.
    Oro?

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'to close the dow window when done use the Environ("COMSPEC") functio
    'this will find the command com no matter where stored on system
    
    'this is your form code
    
    Option Explicit
    
    Private Declare Function ShellExecute Lib _
    "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpOperation As String, _
    ByVal lpFile As String, ByVal lpParameters As String, _
    ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    
    
    Private Sub Command1_Click()
    
        Dim h As Long
        h = Shell(Environ("COMSPEC") & " /C yourpath/yourfile.ext")
        DoEvents
     
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    51
    Thanx a lot!
    Oro?

  4. #4
    Guest
    Or use SendMessage.
    Code:
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private Const WM_CLOSE = &H10
    
    Private Sub Command1_Click()
        Dim hDos As Long
        hDos = FindWindowEx(0, 0, "tty", "MS-DOS Prompt")
        
        If hDos <> 0 Then
            SendMessage hDos, WM_CLOSE, 0, 0
            DestroyWindow hDos
        End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width