Results 1 to 2 of 2

Thread: How do I get notified when a called exe is terminated?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Bangalore
    Posts
    3

    How do I get notified when a called exe is terminated?

    While executing my VB application, I am calling a third party exe file within my VB application. How do I get notified when the third party exe that I am calling is terminated?

    Can I achieve this using API's? If yes, what is the procedure?

  2. #2
    Matthew Gates
    Guest
    Try this:


    VB Code:
    1. Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    2. Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    3. Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
    4. Const STILL_ACTIVE = &H103
    5. Const PROCESS_QUERY_INFORMATION = &H400
    6.  
    7. Sub ShellAndWait(ByVal sProgram As String)
    8.  
    9.          Dim hProcess As Long
    10.          Dim RetVal As Long
    11.          'The next line launches JobToDo as icon,
    12.  
    13.          'captures process ID
    14.          hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(sProgram, 1))
    15.  
    16.          Do
    17.  
    18.              'Get the status of the process
    19.              GetExitCodeProcess hProcess, RetVal
    20.  
    21.              'Sleep command recommended as well as DoEvents
    22.              DoEvents: Sleep 100
    23.  
    24.          'Loop while the process is active
    25.          Loop While RetVal = STILL_ACTIVE
    26.          Msgbox "App has been unloaded!"
    27. End Sub
    28.  
    29. '[b][u]Usage[/u][/b]
    30.  
    31. Private Sub Command1_Click()
    32.     Call ShellAndWait("C:\App\App.exe")
    33. 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