Jump to content

Recommended Posts

Posted

hey

I wonder if there is a possibility to do this in Autoit ? I've to make sure that my application is closed properly to prevent crahses / errors

in VB.NET I was able to do it by :

                AddHandler Microsoft.Win32.SystemEvents.SessionEnding, AddressOf myfunctions_end_mywork
 

I found an old example here : but its not working 

 

 

Posted

you need to register a function to be called when the script receives the termination signal from the system. in this function, you can detect cause of termination by a built-in macro. this is how it can be done:

OnAutoItExitRegister('OnExit')

; your script here (includes, globals, main loop, functions)
While True
    Sleep(10)
WEnd

Func OnExit()
    Switch @exitMethod
        Case 0, 1, 2
            ; do stuff related to normal exit
        Case 3
            ; do stuff related to log off
        Case 4
            ; do stuff related to shutdown/restart
    EndSwitch
EndFunc   ;==>OnExit

look at the help file for relevant function OnAutoItExitRegister() and macro @exitMethod.

keep in mind that the exit function should be very short and finish its job quickly, or Windows will kill your script if it does not respond in due time. so don't start opening IE windows or perform database maintenance here. do some logging, raise a flag, no more.

Signature - my forum contributions:

  Reveal hidden contents

 

Posted
  On 5/2/2016 at 7:10 PM, orbs said:

you need to register a function to be called when the script receives the termination signal from the system. in this function, you can detect cause of termination by a built-in macro. this is how it can be done:

OnAutoItExitRegister('OnExit')

; your script here (includes, globals, main loop, functions)
While True
    Sleep(10)
WEnd

Func OnExit()
    Switch @exitMethod
        Case 0, 1, 2
            ; do stuff related to normal exit
        Case 3
            ; do stuff related to log off
        Case 4
            ; do stuff related to shutdown/restart
    EndSwitch
EndFunc   ;==>OnExit

look at the help file for relevant function OnAutoItExitRegister() and macro @exitMethod.

keep in mind that the exit function should be very short and finish its job quickly, or Windows will kill your script if it does not respond in due time. so don't start opening IE windows or perform database maintenance here. do some logging, raise a flag, no more.

Expand  

thanks a lot :D

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
×
×
  • Create New...