Sign in to follow this  
Followers 0
VelvetElvis

Capture close event (non-GUI app)

8 posts in this topic

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.

Share this post


Link to post
Share on other sites



Use function "OnAutoItExitRegister": Registers a function to be called when AutoIt exits


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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. ;)

Share this post


Link to post
Share on other sites

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 exe

The 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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

That's pretty slick. Never would've occurred to me.

Thanks!

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I take it these are known pop-ups? You wouldn't be able to handle unknown pop-ups, would you?

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0