Results 1 to 4 of 4

Thread: unloading an non-VB related app

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    5

    unloading an non-VB related app

    I'm opening an .exe through a invisible MDI form.
    How can I unload this .exe afterwards

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    what is the executables window caption?

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    da_silvy asked about the caption of the open window because that is what is used to close another running application (regardless of how it got running). If you know the caption, then use this.
    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    2. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    3.  
    4. Private Const WM_CLOSE = &H10
    5. Private Const WM_QUIT = &H12
    6.  
    7. Private Sub Command1_Click()
    8. Dim CloseIt As Long
    9. CloseIt = FindWindow(vbNullString, "Caption Of Window To Be Closed")
    10. PostMessage CloseIt, WM_CLOSE, CLng(0), CLng(0)
    11. End Sub

  4. #4
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    2. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    3.  
    4. Private Const WM_CLOSE = &H10
    5. Private Const WM_QUIT = &H12
    6.  
    7. Private Sub Command1_Click()
    8. Dim CloseIt As Long
    9. CloseIt = FindWindow(vbNullString, "Caption Of Window To Be Closed")
    10. If CloseIt <> 0 Then PostMessage(CloseIt, WM_CLOSE, CLng(0), CLng(0))
    11. End Sub

    It's a better idea to only post the message if a window is found
    I think it might hang otherwise


    If it's an office program, you can close it with other methods also

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