Jump to content

Terminating a commandline-program with exit of Autolt-Script?


Recommended Posts

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

Thanks, it works fine! :D

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? :D

Link to comment
Share on other sites

  • Moderators

Thanks, it works fine! :D

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? :D

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 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

Thanks, it works fine! :D

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? :D

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

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? :D

To which documentation do you refer? (Or am i blind? :D )

Thanks

Link to comment
Share on other sites

  • Moderators

Thanks, works perfect!

But - do not why - i can't find nothing about @ExitCode or @ExitMethod in the help file of AuotIt? :D

To which documentation do you refer? (Or am i blind? :D )

Thanks

I 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

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