Klexen Posted July 5, 2007 Share Posted July 5, 2007 (edited) I was wondering if you can force your program to terminate (without use of killing process with task manager) if it gets hung up. In some of my functions that run I have WinWaitActive command or similar, and lets say for whatever reason that window could never be active, the program will hang until it is and you can't do anything. Is there a way to set a hotkey to force your program to terminate, even if it's stuck in a pause state from function not being completed. For instance, Say I want my program to run several different functions at the click of the button, and while those functions are running, I want to blockinput. Then after functions run enable input. Well if the program hangs during a function, input would be blocked for good. Any ideas? Did what I say make sense? Heh. Edited July 5, 2007 by Klexen Link to comment Share on other sites More sharing options...
herewasplato Posted July 5, 2007 Share Posted July 5, 2007 Look at WinClose and WinKill. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
AutoItKing Posted July 5, 2007 Share Posted July 5, 2007 ProcessClose. http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script] Link to comment Share on other sites More sharing options...
Klexen Posted July 5, 2007 Author Share Posted July 5, 2007 Yeah but will those work even if program is stuck in a function? Or would I need to run a seperate script to set a hotkey to kill the program? Link to comment Share on other sites More sharing options...
mikehunt114 Posted July 5, 2007 Share Posted July 5, 2007 As long as your script isn't hung up, all of the above should close your app. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
herewasplato Posted July 5, 2007 Share Posted July 5, 2007 Yeah but will those work even if program is stuck in a function? Or would I need to run a seperate script to set a hotkey to kill the program?You can write your functions so that they will never get stuck - they always have a timeout and they pass window info to an "Exit function" that closes your window of interest and unblocks user inputs... then it can exit the script of just display an error MsgBox. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Xenobiologist Posted July 5, 2007 Share Posted July 5, 2007 Hi, or use ablibEnable to check every x ms for something. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
BullGates Posted July 5, 2007 Share Posted July 5, 2007 There's a function for that (sorry not to mention the author, but I have it on my snipplets library): If _NotResponding("TITLE HERE", "TEXT HERE[OPTIONAL]", 1) Then; The last parameter indicates whether you want to close the hung app or not. MsgBox(0, "", "Hung Application, closing app now.") Else MsgBox(0, "", "Application running as intended.") EndIf Func _NotResponding($title, $text, $closeIfHung = 0) $hWnd = WinGetHandle($title, $text) If $hWnd == "" Then MsgBox(0, "Error", "Could not find window") Exit 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 ;==>_NotResponding [topic="51913"]Restrict USB Storage usage to group membership[/topic] * [topic="48699"]Using nircmd library[/topic] * Some admin notes Link to comment Share on other sites More sharing options...
ResNullius Posted July 6, 2007 Share Posted July 6, 2007 There's a function for that (sorry not to mention the author, but I have it on my snipplets library):Credit where credit is due: author = neogia http://www.autoitscript.com/forum/index.ph...st&p=176988 Link to comment Share on other sites More sharing options...
ChrisL Posted July 6, 2007 Share Posted July 6, 2007 (edited) The winwaitactive, winwait commands have a timeout period option, so why don't you set a timeout period and always check on the next line to see if the window is active, visible ect, if not then come out of the function and do whatever else you need to do to get to where you want to be. Edit: Added crude example Do $exists = WaitForWindow("Untitled - Notepad","",10) If $exists = 0 then Msgbox(0,"Failure","Notepad doesn't exist") Run ("Notepad.exe") Else Msgbox(0,"Success","Notepad exists") EndIf Until $exists = 1 Func WaitForWindow($win,$Txt="",$timeout=0) WinWait($win,$Txt,$Timeout) If WinExists($win,$Txt) then Return 1 Else Return 0 EndIf EndFunc Edit2: You can do the same with this code and not using a separate function, but the example above showed you how to come out of your function Do $exists = WinWait("Untitled - Notepad","",10) If $exists = 0 then Msgbox(0,"Failure","Notpead doesn't exist") Run ("Notepad.exe") Else Msgbox(0,"Success","Notpead exists") EndIf Until $exists = 1 Edited July 6, 2007 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Klexen Posted July 6, 2007 Author Share Posted July 6, 2007 Thanks guys! I got somethin workin to do it now! 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