VelvetElvis Posted April 20, 2012 Posted April 20, 2012 Maybe it's because it's Friday and I'm just burnt, but I can't find the answer to this one. Simply put, I need to trap the application close event for a non-GUI app. I have an app that pings a list of several critical machines every 15 minutes and logs errors. But I also would like to trap and log when the application was closed by a user. With a GUI, I just use this: Case $GUI_EVENT_CLOSE ; Write to log file Exit However, with a non-GUI app, I don't know how, or where to put it. It's probably going to be embarrasingly simple, but I'm stumped.
water Posted April 20, 2012 Posted April 20, 2012 Use function "OnAutoItExitRegister": Registers a function to be called when AutoIt exits My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
VelvetElvis Posted April 20, 2012 Author Posted April 20, 2012 Thank you water! I have this line in my code as well: Opt("TrayMenuMode", 1) ; No tray menu, and no way to pause from tray So the only way to close the app is via the Windows task manager. It appears that OnAutoItExitRegister doesn't work on this kind of forced closure. :-( Thanks again for the head's up on this. Definitely going in my hints file.
water Posted April 20, 2012 Posted April 20, 2012 So the only way to close the app is via the Windows task manager.To catch this type of event you need a monitoring script that does a ProcessExist every x seconds and then logs a message or whatever and then exits.I usually do it this way:Main process starts the monitoring process and passes the ProcessId plus interval in seconds as paramters to the monitoring exeThe monitoring exe runs in a loop and checks the existance of the passed ProcessID every x seconds. If the process does not exist it writes a log message to a file and exits My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
VelvetElvis Posted April 20, 2012 Author Posted April 20, 2012 That's pretty slick. Never would've occurred to me. Thanks!
water Posted April 20, 2012 Posted April 20, 2012 It's an approach I use in my OutlookEX UDF to wait for pop ups and click them away. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
VelvetElvis Posted April 20, 2012 Author Posted April 20, 2012 I take it these are known pop-ups? You wouldn't be able to handle unknown pop-ups, would you?
water Posted April 20, 2012 Posted April 20, 2012 Yes. You have somehow to decide if the popup is a popup you want to react upon. This can be the window title, some text, a button ID etc. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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