unexpectedpanda Posted September 24, 2012 Share Posted September 24, 2012 (edited) Hi all,I've embarked on a huge clean up of my code project, trying to properly name variables, fix functions, remove bloat etc. The project is designed to return a bloatware and crapware filled laptop to as clean as possible, and to remove any processes that may interrupt a following script that benchmarks the machine.Throughout the project, there's a status bar displayed at the top left, with a big "stop script" button under it. Ideally, that button should run the function _QuitAutoIt() immediately regardless of what the situation is on screen.There is one particular bit though, where the stop script button simply doesn't work. I believe it's related to interrupting a function, but I can't seem to get this to work, and the functions that need to be interrupted can't really be put inside a handy loop to execute as per the examples. For now, I've had to fall back on a keyboard shortcut (CTRL+ALT+Q) that does succesfully terminate the program whenever I like.I've included some sample code. It's been excised from the rest of the codebase and some function placeholders have been put in so it's easier for other people to view. As such, there's likely some variables and functions hanging around that aren't used, but can be safely ignored.When the code is run, it first loads the progress bar, then a GUI asking which program to remove. At this point, the stop script button works. Click one of the program buttons though, and stop script button stops working. Take in mind than when you press a button, a function is executed that is a once off process -- it can't be looped._GetDPI is just a support file, the rest of the _ files are where the action happens. The main script file is example.au3.I'd love some help here if possible. Thanks for your time, if you're kind enough to give it example.zip Edited September 25, 2012 by unexpectedpanda Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 24, 2012 Moderators Share Posted September 24, 2012 unexpectedpanda, Are you sure you want to interrupt the removal process before it terminates? Surely that could leave the system in a very unstable state and you would be better served waiting until the removal had finished. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
unexpectedpanda Posted September 24, 2012 Author Share Posted September 24, 2012 An excellent point! I'd just like to terminate my AutoIt script in this instance. The removal programs are separate .exes (automated by the script) that I'm happy to allow to continue so things don't break, or for the user to manually cancel. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 24, 2012 Moderators Share Posted September 24, 2012 unexpectedpanda, In that case I suggest (based on the scripts you posted) that you change the "removal" functions to read something like this : Func _RemoveProgramOne() ;Dummy function for forums example If WinExists("Program removal") Then GUIDelete($hRemoveProgramGUI) _ProgressStatus("Removing Program One", 1) Run("RemoveProgOne.exe") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< May need more parameters ;) EndFunc ;==>_RemoveProgramOne That way the removal app runs in a separate thread and your button enables you to quit the main AutoIt script at any time while leaving the removal app running to completion. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
unexpectedpanda Posted September 24, 2012 Author Share Posted September 24, 2012 Thanks Melba -- if only it were so simple though. The full version of the AutoIt script interacts with the removal programs, waiting for certain window titles to appear, clicking buttons, sometimes even moving the mouse. I can post exact code if you like, I'm just conscious that I'm shutting down things like antivirus and I don't really want to be responsible for putting code out into public that people could use maliciously. Link to comment Share on other sites More sharing options...
unexpectedpanda Posted September 24, 2012 Author Share Posted September 24, 2012 (edited) Okay, I've come up with a benign compromise, I think If I can interrupt this with the stop script button: Func _RemoveProgramOne() ;Dummy function for forums example If WinExists("Program removal") Then GUIDelete($hRemoveProgramGUI) _ProgressStatus("Removing Program One", 1) Run("calc.exe") WinWait("Calculator") WinActivate("Calculator") ControlClick("Calculator","","[CLASS:Button; INSTANCE:9]") ControlClick("Calculator","","[CLASS:Button; INSTANCE:23]") ControlClick("Calculator","","[CLASS:Button; INSTANCE:10]") Sleep(2000) WinActivate("Calculator") Send("{Enter}") MsgBox(0,"","Hello!") While 1 Sleep(20000) WEnd EndFunc ;==>_RemoveProgramOne Then all will be solved If it's not possible, I shall have to find a workaround Edited September 24, 2012 by unexpectedpanda Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 24, 2012 Moderators Share Posted September 24, 2012 unexpectedpanda,This is getting complex. I suggest that you try to do something like this:- Run the removal app in a separate thread as shown above allowing the button to become active, setting a "Running" flag to show that it is active.- If the button is pressed then:-- If the "Running" flag is set, hide the various GUIs making it look as if the script has ended and set another "Exit" flag to show that the button has been pressed.-- If the "Running" flag is not set, then exit immediately- Once the removal app has ended along with that part of the script, check the "Exit" flag and exit the script (all the tidying up runs at this point) if it is set. If it is not set then clear the "Running" flag and continue.How does that sound? Now you appear to exit at once if the button is pressed, but in reality the script continues to a suitable break point if required. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
unexpectedpanda Posted September 24, 2012 Author Share Posted September 24, 2012 It is complex, I agree. Moreso since the removal apps need user interaction. Looks like we'll have to work around the issue, I'll give your suggestions a shot. Thanks for your help Melba Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 24, 2012 Moderators Share Posted September 24, 2012 unexpectedpanda,Glad I could help. I use something similar to the "flag" solution I proposed in one of my scripts and I have found it a reliable way to deal with the situation. Do come back if you run into any problems. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
unexpectedpanda Posted September 25, 2012 Author Share Posted September 25, 2012 Got the stop script button working by implementing a flag as suggested and moving all of the commands after the program execution out of the function, and into the main script. Thanks again Melba 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