Jump to content

Recommended Posts

Posted

Hello everyone,

after searching this forum ower and ower again i couldn't find solution to my problem or i didn't understand hints that were given in some of the threads i found.

Let me explain what am i trying to do.

I have a program that hangs from time to time for many different reasons. Now what am i trying to do is to write an AutoIt script that will be checking if program is running as it should or if its hanged/crashed/not responding (i dont know if those program states are all the same).

After some searching on forum i found a code which is calling a user32.dll function called "IsHungAppWindow" (see code bolow):

If _NotResponding("Calculator", "", 1)  Then
    MsgBox(1,"Test","Process hanged")
Else
    MsgBox(1,"Test","Process not hanged")
EndIf

Func _NotResponding($title, $text, $closeIfHung = 0)
    $hWnd = WinGetHandle($title, $text)

If $hWnd == "0" Then
MsgBox(1,"Tets","Window not found")
EndIf
    $retArr = DllCall("user32.dll", "int", "IsHungAppWindow", "hwnd", $hWnd)
    If @error == 0 Then
        If $retArr[0] == 1 Then
            If $closeIfHung Then
                ProcessClose(WinGetProcess($title, $text))
            EndIf
            Return 1
        EndIf
    Else
        Return 0
    EndIf
EndFunc

I was using windows Calculator to test this code. So what i did was i downloaded some program from CodeProject which is desigend to Suspend process ... and above posted code does not return correct MSGBox.

I am not sure if code doesnt work or the entire logic is wrong?

I hope some of you could help me a bit.

Thank you for your replays.

Best regards.

Posted

I just realized i have another option but i dont know if its doable.

Is there a settings in windows 7 where you can choose to automatically close non responding programs or something similar.

I could do a simple procesexist search every x seconds and wouldnt need to check if application is running or its hanged.

Posted
In this post the function SendMessageTimeoutW is discussed. I was thinking all along that this might be a good method to check if a window is hung. Set the flags correctly (SMTO_ABORTIFHUNG, SMTO_ERRORONEXIT) with an acceptable timeout (5 seconds?), send something like WM_NULL or an empty WM_COPYDATA or something else not interfering with the program itself and wait for a response (0 on timeout)... will probably have time in the evening to try something :blink:...
Posted (edited)

  On 7/2/2010 at 10:13 AM, 'KaFu said:

In this post the function SendMessageTimeoutW is discussed. I was thinking all along that this might be a good method to check if a window is hung. Set the flags correctly (SMTO_ABORTIFHUNG, SMTO_ERRORONEXIT) with an acceptable timeout (5 seconds?), send something like WM_NULL or an empty WM_COPYDATA or something else not interfering with the program itself and wait for a response (0 on timeout)... will probably have time in the evening to try something ;)...

Ok i will try this even tho i am most certain i will fail :P.

I am wondering if there is a difference when program is :

a) hanged

:blink: not responding

c) something else.

In the mean while i have found some "solutio" on this website. Creating short cut on desktop which closes any non responging programs in one click so i can simply call it from my script.

Any more feedback is welcomed.

thanks for now.

Edit: I have found an even better solution ... what you need to do is a bit of regedit. Link

Edited by amakrkr
Posted

'IsHungAppWindow' will work in certain scenarios. However, applications with threads that are Suspended will not usually be reported as 'Hung'. Calling a function with 'SendMessageTimeout' is a good secondary detection mechanism though, and if that fails (when called with flag 'SMTO_ABORTIFHUNG') then you can call 'GetLastError' and see if it returns error code 1460 (ERROR_TIMEOUT). I use both of these methods in my 'Full Screen Crash Recovery' program, and it works well.

My contributions:

  Reveal hidden contents

Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFsProcess CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen)Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery

Wrappers/Modifications of others' contributions:

_DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity)

UDF's added support/programming to:

_ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne)

(All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)

Posted

  On 7/2/2010 at 7:01 PM, 'Ascend4nt said:

'IsHungAppWindow' will work in certain scenarios. However, applications with threads that are Suspended will not usually be reported as 'Hung'. Calling a function with 'SendMessageTimeout' is a good secondary detection mechanism though, and if that fails (when called with flag 'SMTO_ABORTIFHUNG') then you can call 'GetLastError' and see if it returns error code 1460 (ERROR_TIMEOUT).

Thanks for the infos m8, will give it a try :P (vacation next week ;))...

  On 7/2/2010 at 7:01 PM, 'Ascend4nt said:

I use both of these methods in my 'Full Screen Crash Recovery' program, and it works well.

Just checked it out but saw no source :blink: ...
Posted

  On 7/2/2010 at 8:39 PM, 'KaFu said:

Just checked it out but saw no source :blink: ...

haha, I know. The only project I had that I closed the source on - though who woulda thunk it, its out there (an older version) on some website of course.

Anyway, I was just referring to my app because the method discussed has worked very well for it in detecting pesky crashed/hung applications. I just realized now though that there's a note on the MSDN website about Windows 2000 not returning the right error code when using 'GetLastError'. Argh, guess that should be fixed now..

My contributions:

  Reveal hidden contents

Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFsProcess CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen)Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery

Wrappers/Modifications of others' contributions:

_DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity)

UDF's added support/programming to:

_ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne)

(All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...