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?
Printable View
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?
Try this:
VB Code:
Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long) Const STILL_ACTIVE = &H103 Const PROCESS_QUERY_INFORMATION = &H400 Sub ShellAndWait(ByVal sProgram As String) Dim hProcess As Long Dim RetVal As Long 'The next line launches JobToDo as icon, 'captures process ID hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(sProgram, 1)) Do 'Get the status of the process GetExitCodeProcess hProcess, RetVal 'Sleep command recommended as well as DoEvents DoEvents: Sleep 100 'Loop while the process is active Loop While RetVal = STILL_ACTIVE Msgbox "App has been unloaded!" End Sub '[b][u]Usage[/u][/b] Private Sub Command1_Click() Call ShellAndWait("C:\App\App.exe") End Sub