Sign in to follow this  
Followers 0
roman

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

7 posts in this topic

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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

[center]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.[/center]

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.

[center]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.[/center]

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