Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: hang hanging hung nonresponsive responsive terminate kill
Using the DllCall Function to call the SendMessageTimeout API function you can see if the target application is responding. Then you can terminate it if it is not.
Once the window handle is known it is used in the SendMessageTimeout function along with the SMTO_ABORTIFHUNG and SMTO_BLOCK flags. If the application appears to be hung, SendMessageTimeout returns with a zero value. A timeout period can be specified.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/messagesandmessagequeues/messagesandmessagequeuesreference/messagesandmessagequeuesfunctions/sendmessagetimeout.asp Here is my attempt at the code:
Run('Notepad','') windowname = '~Notepad' hwnd = DllHwnd(windowname) DaDll=Strcat(DirWindows(1),"USER32.DLL") WININICHG=26 SMTO_ABORTIFHUNG = 2 SMTO_BLOCK = 1 TIMEOUT = 1500; 15 seconds lpdwResult = Binaryalloc(4) BinaryEodSet(lpdwResult,0) ret = DllCall( DaDll, long:"SendMessageTimeoutA", long:hwnd, long:WININICHG, long:0, lpstr:"Environment", long:SMTO_ABORTIFHUNG|SMTO_BLOCK,long:TIMEOUT, lpbinary:lpdwResult) if ret== 0 Message('Notice','Application is Non Responsive') IntControl (56, windowname, 0, 0, 0) ;Terminate an application. else Message('Notice','Application is Responsive') Endif BinaryFree(lpdwResult)
Article ID: W16988
File Created: 2007:07:03:14:27:30
Last Updated: 2007:07:03:14:27:30