how do i keep an external program running and let it automatically restart if closed. (without timer)
Printable View
how do i keep an external program running and let it automatically restart if closed. (without timer)
You could use the SetTimer API function to keep checking for the program and if it detects no window, than re-open that program.
how does that work?
Something like this:
VB Code:
'Module code: Dim Wnd As Long Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, _ ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As _ Long) As Long Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, _ ByVal nIDEvent As Long) As Long Public Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" (ByVal lpClassName As String, ByVal _ lpWindowName As String) As Long Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) Wnd = FindWindow("ProgramClass", "ProgramTitle") If Wnd = 0 Then Shell "Program.exe", 1 End Sub Sub StartTimer(ByVal lInterval) SetTimer Form1.hwnd, 100, lInterval, AddressOf TimerProc End Sub Sub StopTimer() KillTimer Form1.hwnd, 100 End Sub 'Form Code: Private Sub Form_Activate() StartTimer 500 End Sub Private Sub Form_Unload(Cancel As Integer) StopTimer End Sub
thanks man!