Results 1 to 10 of 10

Thread: Urgent - Detect Crash + Kill Program

Threaded View

  1. #4
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    You need to add code to restart outlook, but the code to close if the app is hung should work although untested, so you might have to fiddle. Also it assumes only one version of outlook at any one time.

    VB Code:
    1. Option Explicit
    2.  
    3.  
    4.  
    5.  
    6. Private Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)
    7. Private Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long
    8. Private Const WM_NULL = &H0
    9. Private Const SMTO_ABORTIFHUNG = &H2
    10.  
    11. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    12. Const PROCESS_ALL_ACCESS = &H1F0FFF
    13.  
    14. Private Declare Function TerminateProcess& Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long)
    15. Private Declare Function GetWindowThreadProcessId& Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long)
    16. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    17.  
    18.  
    19. Sub RestartOutlookIfHung()
    20. Dim lhwnd&, pid&, hp&
    21.  
    22. lhwnd = FindWindow("rctrl_renwnd32", vbNullString)
    23. If (SendMessageTimeout(lhwnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 10, 0) = 0) Then
    24.     GetWindowThreadProcessId lhwnd, pid
    25.     hp = OpenProcess(PROCESS_ALL_ACCESS, 0&, pid)
    26.     TerminateProcess hp&, 0&
    27.     CloseHandle hp
    28. End If
    29.  
    30. 'You add code to restart outlook here
    31. End Sub
    Last edited by Nucleus; Aug 15th, 2001 at 05:53 PM.

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