Roman Posted June 7, 2006 Share Posted June 7, 2006 Hi My AutoIt-Scripts executes a commandline-program with RunWait(@COMSPEC & " /c" ...) If i terminate the running script with right-click on the trayicon (Exit), the commandline-program continious and will not be terminated - that is not nice. How can i guarantee that a startet und running program terminates, if the "calling" AutoIt-Script will be terminated manually? Greetings, Roman. Link to comment Share on other sites More sharing options...
Emperor Posted June 7, 2006 Share Posted June 7, 2006 Here's a short example using 'OnExitFunc': AutoItSetOption("OnExitFunc", "CleanUp") RunWait("notepad.exe") Exit Func CleanUp() If ProcessExists("notepad.exe") Then ProcessClose("notepad.exe") EndFunc Link to comment Share on other sites More sharing options...
Roman Posted June 7, 2006 Author Share Posted June 7, 2006 Thanks, it works fine! But this raises a new question: how can i differentiate between a "regular", wantet exit (within the code) and a manually termination with a right-click on tray-icon? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 7, 2006 Moderators Share Posted June 7, 2006 (edited) Thanks, it works fine! But this raises a new question: how can i differentiate between a "regular", wantet exit (within the code) and a manually termination with a right-click on tray-icon? Can you provide a source file of what your talking about? Are you using a GUI (Is that what you mean)?.... Is there somewhere in your script that you have If/Then Exit? Edit: This may or may not help:Global $MyExit = False If MsgBox(36, 'Exit', 'Would you like to exit?') = 6 Then $MyExit = True Exit EndIf Func OnAutoItExit() If $MyExit = False Then MsgBox(64, 'Info:', 'You exited from a different option other than script');~ Some exit option if they are exiting from something other than what you want Else MsgBox(64, 'Info', 'You exited from the msgbox') EndIf EndFunc Edited June 7, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
SlimShady Posted June 7, 2006 Share Posted June 7, 2006 Thanks, it works fine! But this raises a new question: how can i differentiate between a "regular", wantet exit (within the code) and a manually termination with a right-click on tray-icon? Check the documentation on the OnAutoItExit() page. Inside the function, @ExitCode can be used to retrieve the code set by the exit statement. The mode of exit can be retrieved with @ExitMethod. 0 | Natural closing. 1 | close by Exit function. 2 | close by clicking on exit of the systray. 3 | close by user logoff. 4 | close by Windows shutdown. Example: Opt("OnExitFunc", "endscript") MsgBox(0,"","first statement") Func endscript() MsgBox(0,"","after last statement " & @EXITMETHOD) EndFunc Link to comment Share on other sites More sharing options...
Roman Posted June 8, 2006 Author Share Posted June 8, 2006 Check the documentation on the OnAutoItExit() page.Thanks, works perfect!But - do not why - i can't find nothing about @ExitCode or @ExitMethod in the help file of AuotIt? To which documentation do you refer? (Or am i blind? )Thanks Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 8, 2006 Moderators Share Posted June 8, 2006 Thanks, works perfect!But - do not why - i can't find nothing about @ExitCode or @ExitMethod in the help file of AuotIt? To which documentation do you refer? (Or am i blind? )ThanksI don't know if you're strictly replying to SlimShady or if your saying my example worked... but you might download the latest beta to find ALL the functionality that we use here on the forum. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
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