# Keyword Reference

Func OnAutoItExit ()...EndFunc

Defines a user-defined function that will be called when the script exit.

Func OnAutoItExit ( )
...
EndFunc

Parameters

None.

Remarks

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.

Related

Func OnAutoItStart (), OnExitFunc (Option)

Example

Opt("OnExitFunc", "endscript")
MsgBox(0,"","first statement")
Func endscript()
MsgBox(0,"","after last statement " & @EXITMETHOD)
EndFunc