WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Check if Application is Responsive

 Keywords: hang hanging hung nonresponsive responsive terminate kill 

Question:

How can I check if a current application or process has stopped responding? Is there a function in the process extender to check this?

Answer:

There is no clear definition of an application hanging. Typically the application is busy processing. But from a user's standpoint it has stopped responding.

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