Jump to content

OnExit Function


Recommended Posts

I need to do something like this:

OnAutoItExitRegister("OnExit")

func OnExit()
    Msgbox(0,'script closed','')
EndFunc

while 1
Sleep(1)
WEnd

This works great if the script closes as expected. But if you end task via task manager, script closes by error, or some other form of unexpected exit this does not work. I've searched the forums and theres stuff like 'run a separate exe to monitor the other by ProcessExists' but what if the monitor program exits unexpectedly? Then what? I searched the forums, couldn't find anything. There used to be a Opt("OnExit","function") but I guess OnAutoItExitRegister replaced it. Help would be much appreciated.

Link to comment
Share on other sites

I'm not sure there's anything that you can do for such an abrupt program termination. Your script would simply just stop midstream.

Maybe you could have two scripts except they monitor each other and when one script exits then certain actions are taken.

Say you have 'main script' and then 'monitor script'. 'Monitor script' will monitor your 'main script' for any abrupt termination and if so will pop up a msgbox. However, your 'main script' will monitor your 'monitor script' and if your 'monitor script' exits then your 'main script' will respawn your 'monitor script'.

Edited by jaberwocky6669
Link to comment
Share on other sites

I'm not sure there's anything that you can do for such an abrupt program termination. Your script would simply just stop midstream.

Maybe you could have two scripts except they monitor each other and when one script exits then certain actions are taken.

Say you have 'main script' and then 'monitor script'. 'Monitor script' will monitor your 'main script' for any abrupt termination and if so will pop up a msgbox. However, your 'main script' will monitor your 'monitor script' and if your 'monitor script' exits then your 'main script' will respawn your 'monitor script'.

hrmm... well I was just asking cause i remember in vb.net you could do something like that. It would skip whatever your doing and hit that function before complete exit. but ya.. both the scripts could monitor eachother that would work given my situation. I just didn't want to change the code on my other script Thanks man!

I'll post my code once I'm done for forum reference b/c im monitoring over the network (which I already have programmed).

Link to comment
Share on other sites

Say you have 'main script' and then 'monitor script'. 'Monitor script' will monitor your 'main script' for any abrupt termination and if so will pop up a msgbox. However, your 'main script' will monitor your 'monitor script' and if your 'monitor script' exits then your 'main script' will respawn your 'monitor script'.

Hmm, "Who's watching the watcher?" :idea:

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...