amakrkr Posted July 2, 2010 Share Posted July 2, 2010 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. guestscripter 1 Link to comment Share on other sites More sharing options...
amakrkr Posted July 2, 2010 Author Share Posted July 2, 2010 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. Link to comment Share on other sites More sharing options...
KaFu Posted July 2, 2010 Share Posted July 2, 2010 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 ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
amakrkr Posted July 2, 2010 Author Share Posted July 2, 2010 (edited) 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 .I am wondering if there is a difference when program is :a) hanged not respondingc) 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 July 2, 2010 by amakrkr Link to comment Share on other sites More sharing options...
Ascend4nt Posted July 2, 2010 Share Posted July 2, 2010 '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: 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 UDFs | Process 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) Link to comment Share on other sites More sharing options...
KaFu Posted July 2, 2010 Share Posted July 2, 2010 '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 (vacation next week )...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 ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Ascend4nt Posted July 3, 2010 Share Posted July 3, 2010 Just checked it out but saw no source ...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: 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 UDFs | Process 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) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now