Results 1 to 5 of 5

Thread: keep program running

  1. #1
    Chinese Leper
    Guest

    keep program running

    how do i keep an external program running and let it automatically restart if closed. (without timer)

  2. #2
    Matthew Gates
    Guest
    You could use the SetTimer API function to keep checking for the program and if it detects no window, than re-open that program.

  3. #3
    Chinese Leper
    Guest
    how does that work?

  4. #4
    Matthew Gates
    Guest
    Something like this:


    VB Code:
    1. 'Module code:
    2.  
    3. Dim Wnd As Long
    4.  
    5. Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, _
    6. ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As _
    7. Long) As Long
    8.  
    9. Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, _
    10. ByVal nIDEvent As Long) As Long
    11.  
    12. Public Declare Function FindWindow Lib "user32" _
    13. Alias "FindWindowA" (ByVal lpClassName As String, ByVal _
    14. lpWindowName As String) As Long
    15.  
    16. Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
    17.     Wnd = FindWindow("ProgramClass", "ProgramTitle")
    18.     If Wnd = 0 Then Shell "Program.exe", 1
    19. End Sub
    20.  
    21. Sub StartTimer(ByVal lInterval)
    22.     SetTimer Form1.hwnd, 100, lInterval, AddressOf TimerProc
    23. End Sub
    24.  
    25. Sub StopTimer()
    26.     KillTimer Form1.hwnd, 100
    27. End Sub
    28.  
    29.  
    30. 'Form Code:
    31.  
    32.  
    33. Private Sub Form_Activate()
    34.     StartTimer 500
    35. End Sub
    36.  
    37. Private Sub Form_Unload(Cancel As Integer)
    38.     StopTimer
    39. End Sub

  5. #5
    Chinese Leper
    Guest
    thanks man!

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