benlinkknilneb
Programmer
(This is cross-posted in the Win API forum)
Hi all,
I've been working on a program to reboot my computer when an application crashes. I thought I had it figured out; I was using some code I found to detect whether the program was hung or not. However, I'm getting the "This program has performed an illegal operation..." message in the app that I'm checking on. Apparently, this isn't sufficient for the current code to say that the program is "hung", and it won't reboot until someone clicks the button to cancel the window. Below is the current code that I'm using to detect the state of the app:
Can anyone suggest a better way to do this, that will ignore the "illegal operation" message and reboot?
Ben
Hi all,
I've been working on a program to reboot my computer when an application crashes. I thought I had it figured out; I was using some code I found to detect whether the program was hung or not. However, I'm getting the "This program has performed an illegal operation..." message in the app that I'm checking on. Apparently, this isn't sufficient for the current code to say that the program is "hung", and it won't reboot until someone clicks the button to cancel the window. Below is the current code that I'm using to detect the state of the app:
Code:
Private Sub CheckStatus(hWnd As Long)
Dim lPid As Long
Dim lProcess As Long
If WindowIsHung(hWnd) Then
lProcess = GetWindowThreadProcessId(hWnd, lPid)
lProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, lPid)
TerminateProcess lProcess, 0&
ShutDownWindows True, True
End
End If
End Sub
Private Function WindowIsHung(hWnd As Long) As Boolean
Dim lResult As Long
WindowIsHung = (SendMessageTimeout(hWnd, WM_NULL, 0&, 0&, SMTO_ABORTIFHUNG Or SMTO_BLOCK, 1000, lResult) = False)
End Function
Ben