iXX Posted October 3, 2012 Share Posted October 3, 2012 Hi! Is there any way to detect if a specific application is hanging or not responding or crashing...? Cant use of "ProcesExists()" function, because such app is "still there" - in the task manager list. Thanks for any advance. Link to comment Share on other sites More sharing options...
water Posted October 3, 2012 Share Posted October 3, 2012 What do you mean by "specific application"? An application you've written yourself? What do you mean by "hang"? Running in a loop and eating up all CPU cycles or doing nothing? Waiting for an event to occur (I/O or whatever ...)? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
FireFox Posted October 3, 2012 Share Posted October 3, 2012 @iXXMaybe Br, FireFox. Link to comment Share on other sites More sharing options...
guinness Posted October 3, 2012 Share Posted October 3, 2012 @iXXMaybe Br, FireFox.That can be found in WinAPIEx.au3, the function is called _WinAPI_IsHungAppwindow. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
FireFox Posted October 3, 2012 Share Posted October 3, 2012 (edited) That can be found in WinAPIEx.au3, the function is called _WinAPI_IsHungAppwindow.Let's say I'm oldschool. But thanks for having pointed out the right solution for now.oh yes, I remember now this function but It's not the first thing that came up to my mind... Edited October 3, 2012 by FireFox Link to comment Share on other sites More sharing options...
Skitty Posted October 3, 2012 Share Posted October 3, 2012 Now that I remember, I've seen that function in there. But using the code FF linked, it'll keep your script much smaller and will launch much faster when debugging, except if you turn off Au3Check for it. Anyway, here's an example for detecting a hung app, can be changed to work with other things. expandcollapse popup#include <Array.au3> Global Const $hNTDLL = DllOpen("ntdll.dll") Global Const $hUSER32 = DllOpen("user32.dll") Global Const $hKERNEL32 = DllOpen("kernel32.dll") Global $ChildPID Global $aWinHwnds[1] Global $GlobalWinCount If StringInStr($CmdLineRaw, "WatchMe=", 2) Then $temporariis = StringSplit($CmdLineRaw, "WatchMe=") Monitor($temporariis[$temporariis[0]]) Exit EndIf Switch @Compiled Case True $ChildPID = Run(FileGetShortName(@ScriptFullPath) & " WatchMe=" & @AutoItPID) Sleep(3000) Case False $ChildPID = Run(FileGetShortName(@AutoItExe) & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" WatchMe=' & @AutoItPID) Sleep(3000) EndSwitch MsgBox(64, "Information!", "Process ("&@AutoItPID&") is about to be suspended, after this happens, our "&@CR&"child monitoring script should respond to the event. This may take a few seconds.") _ProcessSuspend(@AutoItPID); simulate a non responsive GUI MsgBox(16, "Information!", "Something happened D:"&@CR&"Obviously we don't have enough rights to suspend a process on this machine :("&@CR&"Too bad lol, try something else :P") Exit ; #INTERNAL FUNCTION# =========================================================================================================== ; Name ..........: Monitor ; Description ...: Monitors the main instance of this script to prevent any unwanted system lockups. ; Syntax ........: Monitor($PID) ; Parameters ....: $PID - PID of our initiating instance. ; Return values .: None ; Example .......: No ; =============================================================================================================================== Func Monitor($PID) Local $aReturn Local $Win = _EnumProcessWindows($PID,0) $Win = $Win[0] While ProcessExists($PID) Sleep(1000) $aReturn = DllCall($hUSER32, "Int", "IsHungAppWindow", "Hwnd", $Win) If @error Or $aReturn[0] Then ExitLoop ;If WinGetState($Win) = 16 Then WinSetState($Win,"",@SW_RESTORE) WEnd ProcessClose($PID) MsgBox(64, "Whoa!", "Seems like something went wrong with our script!" & @CR & @CR & _ "A well trained team of monkeys were dispatched to take care of the problem...") Exit EndFunc ;==>Monitor ; #INTERNAL FUNCTION# =========================================================================================================== ; Name...........: _EnumProcessWindows ; Description....: Enumerates a windows that belong to the specified process. ; Syntax.........: _EnumProcessWindows ( [$PID [, $fVisible]] ) ; Parameters.....: $PID - The PID of the process. ; $fVisible - Specifies whether enumerates the invisible window, valid values: ; |TRUE - Enumerate only visible windows. (Default) ; |FALSE - Enumerate all windows. ; Return values..: Success - The 1D array of window handles. ; Failure - 0 and sets the @error flag to non-zero. ; Author.........: Yashied ; Modified.......: CaptainClucks ; Remarks........: I've slightly modified this for use in this script, only necesary stuff is keept here. ; Related........: __EnumWindowsProc ; Link...........: None ; Example........: No ; =============================================================================================================================== Func _EnumProcessWindows($PID = 0, $fVisible = 1) $GlobalWinCount = 0 Local $Threads = _GetAllProcessThreads($PID) If @error Then Return SetError(1, 0, 0) EndIf Local $hEnumProc = DllCallbackRegister('__EnumWindowsProc', 'int', 'hwnd;lparam') For $I = 0 To UBound($Threads) - 1 DllCall($hUSER32, 'int', 'EnumThreadWindows', 'dword', $Threads[$I][0], 'ptr', DllCallbackGetPtr($hEnumProc), 'lparam', $fVisible) If @error Then ExitLoop EndIf Next DllCallbackFree($hEnumProc) If Not $aWinHwnds[0] Then Return SetError(1, 0, 0) EndIf Return $aWinHwnds EndFunc ;==>_EnumProcessWindows Func __EnumWindowsProc($hWnd, $fVisible) If $fVisible Then Local $aResult = DllCall($hUSER32, "bool", "IsWindowVisible", "hwnd", $hWnd) If @error Then Return 1 If Not $aResult[0] Then Return 1 EndIf $GlobalWinCount += 1 ReDim $aWinHwnds[$GlobalWinCount] $aWinHwnds[$GlobalWinCount - 1] = $hWnd Return 1 EndFunc ;==>__EnumWindowsProc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GetAllProcessThreads ; Description ...: Gets threads in a process ; Syntax ........: _GetAllProcessThreads($iPID) ; Parameters ....: $iPID - Process ID. ; Return values .: Array with thread info ; Author ........: monoceres ; Remarks .......: ; Related .......: _GetAllThreads_ArrHelper, _ThreadSuspend, _ThreadResume ; Link ..........: http://www.autoitscript.com/forum/topic/85728-thread-enumeration-with-createtoolhelp32snapshot/ ; Example .......: No ; =============================================================================================================================== Func _GetAllProcessThreads($iPID) Local $call = DllCall($hKERNEL32, "ptr", "CreateToolhelp32Snapshot", "dword", 0x00000004, "dword", 0) Local $handle = $call[0] Local $RetArr[1][3] Local $te32 = DllStructCreate("dword dwSize;dword cntUsage;dword th32ThreadId;dword th32OwnerProcessID;long tpBasePri;long tpDeltaPri;dword dwFlags;") DllStructSetData($te32, "dwSize", DllStructGetSize($te32)) $call = DllCall($hKERNEL32, "int", "Thread32First", "ptr", $handle, "ptr", DllStructGetPtr($te32)) If DllStructGetData($te32, "th32OwnerProcessID") = $iPID Then _GetAllThreads_ArrHelper($RetArr, $te32) Do $call = DllCall($hKERNEL32, "int", "Thread32Next", "ptr", $handle, "ptr", DllStructGetPtr($te32)) If Not $call[0] Then ExitLoop If DllStructGetData($te32, "th32OwnerProcessID") = $iPID Then _GetAllThreads_ArrHelper($RetArr, $te32) Until True And False _ArrayDelete($RetArr, 0) DllCall($hKERNEL32, "bool", "CloseHandle", "handle", $handle) Return $RetArr EndFunc ;==>_GetAllProcessThreads Func _GetAllThreads_ArrHelper(ByRef $arr, $TE32_Struct) Local $ub = UBound($arr) ReDim $arr[$ub + 1][3] $arr[$ub][0] = DllStructGetData($TE32_Struct, "th32ThreadId") $arr[$ub][1] = DllStructGetData($TE32_Struct, "th32OwnerProcessID") $arr[$ub][2] = DllStructGetData($TE32_Struct, "tpBasePri") EndFunc ;==>_GetAllThreads_ArrHelper ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ProcessSuspend ; Description ...: suspends a process ; Syntax ........: _ProcessSuspend($Process) ; Parameters ....: $Process - An unknown value. ; Return values .: None ; Author ........: The Kandie Man ; Modified ......: CaptainClucks ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _ProcessSuspend($Process) Local $processid = ProcessExists($Process) If $processid Then Local $ai_Handle = DllCall($hKERNEL32, 'int', 'OpenProcess', 'int', 0x1F0FFF, 'int', False, 'int', $processid) Local $i_sucess = DllCall($hNTDLL, "int", "NtSuspendProcess", "int", $ai_Handle[0]) DllCall($hKERNEL32, 'ptr', 'CloseHandle', 'ptr', $ai_Handle[0]) If IsArray($i_sucess) Then Return SetError(0, 0, True) Else Return SetError(1, 0, False) EndIf Else Return SetError(2, 0, False) EndIf EndFunc ;==>_ProcessSuspend Link to comment Share on other sites More sharing options...
iXX Posted October 4, 2012 Author Share Posted October 4, 2012 Very thak You!, especialy FF ang guiness! Thats what I am finding. One more thing, after killing an process, is possible to remove its "dead icon" from system tray? (On Win7/x64). Link to comment Share on other sites More sharing options...
guinness Posted October 4, 2012 Share Posted October 4, 2012 (edited) Yes, use this function. #include <WinAPI.au3> _Taskbar_Refresh() Func _Taskbar_Refresh() ; By rasim - http://www.autoitscript.com/forum/topic/66629-systemtray-refresh/ Local $hTaskBar = _WinAPI_FindWindow("Shell_TrayWnd", "") Local $hParent = ControlGetHandle($hTaskBar, "", "TrayNotifyWnd1") Local $hHandle = ControlGetHandle($hParent, "", "ToolbarWindow321") Local $tWinRect = _WinAPI_GetWindowRect($hHandle) Local $aMouseGetPos = MouseGetPos() Local $iLeft = DllStructGetData($tWinRect, "Left") Local $iRight = DllStructGetData($tWinRect, "Right") Local $iTop = DllStructGetData($tWinRect, "Top") For $i = $iLeft To $iRight MouseMove($i, $iTop, 0) Next MouseMove($aMouseGetPos[0], $aMouseGetPos[1], 0) EndFunc ;==>_Taskbar_Refresh Edited October 4, 2012 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 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