jfornango Posted October 11, 2013 Posted October 11, 2013 Hi all. Been using AutoIT for a few years now, and I love it. Also, the forum has been a valuable resource. Thanks for all the community support. Still, I know that my coding skills aren't quite up to snuff I'm working on a project and could use some assistance on a "best approach" for an issue I've come across. I didn't see an article that really applied, but if there is one, just point me to it. Here's the score, I'm writing an application that will be used to migrate a user's data between two computers. (don't ask why my client isn't using roaming profiles or the profile migration utility. Too much customization for either to work.) Anyway, the backup and restore processes include roughly a dozen steps each. During the entire process, I want the deskside technician to be able to hit a Cancel button, and have the process stop. (this is like an emergency stop) Previous code that I have written is usually a sigle step repeated ad-nauseum, and just uses an GUIGetMsg() to check for an button, which then kills the program with an exit. However, I need to do some house-keeping, including logging the fact that the run was interupted by the user, before terminating. What would be the best approach to accomplish this? Thank you in advance for any and all recommendations.
Moderators Melba23 Posted October 11, 2013 Moderators Posted October 11, 2013 jfornango,Welcome to the AutoIt forum. I suggest you read the Interrupting a running function tutorial in the Wiki - that shows a number of ways of doing what you want to do. 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
jfornango Posted October 31, 2013 Author Posted October 31, 2013 (edited) Ok, so after reading this, it looks like I'm already using one of the methods described. As an example, here are the first two pieces of my backup process. expandcollapse popup; copy the user's desktop $strStatus = "Backing up desktop" GUICtrlSetData ($lblStatus, "Status: " & $strStatus) GUISetState() $rc = DirCopy(@UserProfileDir & "\Desktop", $strTarget & "\Desktop") If $rc = 1 Then FileWriteLine($strProcessLog, _NowTime() & " Desktop copied successfully") Else FileWriteLine($strProcessLog, _NowTime() & " There was an error " & _ "copying the Desktop. Error code " & @error) EndIf ; check for the Cancel button $ctrl_msg = GUIGetMsg() if $ctrl_msg = $btnCancel Then $strStatus1 = "Cancel" _dataCancel() EndIf ; copy the user's IE Favorites $strStatus = "Backing up IE Favorites" GUICtrlSetData ($lblStatus, "Status: " & $strStatus) GUISetState() $rc = DirCopy(@UserProfileDir & "\Favorites", $strTarget & "\Favorites") If $rc = 1 Then FileWriteLine($strProcessLog, _NowTime() & " Favorites copied successfully") Else FileWriteLine($strProcessLog, _NowTime() & " There was an error " & _ "copying the Favorites. Error code " & @error) EndIf ; check for the Cancel button $ctrl_msg = GUIGetMsg() if $ctrl_msg = $btnCancel Then $strStatus1 = "Cancel" _dataCancel() EndIf And for reference, here is the Cancel function Func _dataCancel() Select Case $strStatus1 = "Idle" MsgBox(0, "ALERT", "There is currently no operation to cancel.") Case $strStatus1 = "Backup" $strStatus = "Canceling... Please Wait" GUICtrlSetData($lblStatus, $strStatus) GUISetState() FileWriteLine($strProcessLog, _NowTime() & "Backup cancelled by user.") FileClose($strProcessLog) Exit Case $strStatus1 = "Restore" $strStatus = "Canceling... Please Wait" GUICtrlSetData($lblStatus, $strStatus) GUISetState() FileWriteLine($strProcessLog, _NowTime() & "Restore cancelled by user.") FileClose($strProcessLog) Exit EndSelect EndFunc So, you can see where I am checking for a "cancel" message after each piece of the process. This is works well and coded fairly easily. So far, so good. Here's my problem. What if I discover that a user has a 20 GB folder on their desktop after the backup has started (which makes me want to stop and evaluate the state of the backup location)? Is there a way to interupt the DirCopy command without actually closing the program? I need to be able to update the log file, to show that the process was manually interupted (instead of, say, crashing), and at what point. Edited October 31, 2013 by jfornango
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