Environment Variables

AutoIt

Environment Variables

You can use DOS environment variables anywhere in an AutoIt script. As in DOS batch files, just include the variable enclosed in percent (%) symbols.

For example, if you want to send the current DOS path to the notepad window you could do:

Run, notepad.exe
WinWaitActive, Untitled - Notepad
Send, This is the DOS path %PATH%


e.g. This example sets the variable test and then outputs it in a messagebox.
SetEnv, test, This is some output
MsgBox, 0, Example, %test%


N.B. Because of its special status, if you want to actually use a percent sign without it being changed into a variable, you must use the escape character '\' first.
e.g.
Send, This will send a single percent sign \%

You can also use "SetEnv" to set variables..

N.B. Many AutoIt commands specifically state that they take a variable as a parameter, in these cases the % symbol is NOT used.  A number of the examples that come with AutoIt demonstrate this.