PDA

Click to See Complete Forum and Search --> : keep program running


Chinese Leper
Dec 21st, 2001, 04:48 PM
how do i keep an external program running and let it automatically restart if closed. (without timer)

Matthew Gates
Dec 23rd, 2001, 08:07 PM
You could use the SetTimer API function to keep checking for the program and if it detects no window, than re-open that program.

Chinese Leper
Dec 24th, 2001, 04:05 AM
how does that work?

Matthew Gates
Dec 26th, 2001, 02:17 PM
Something like this:


'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

Chinese Leper
Dec 27th, 2001, 09:19 PM
thanks man!