ErrorLevel

This is a built-in variable that is set to indicate the success or failure of some of the commands (not all commands change the value of ErrorLevel). A value of 0 usually indicates success, and any other value usually indicates failure. You can also set the value of ErrorLevel yourself.

Of special interest is that RunWait sets ErrorLevel to be the exit code of the program it ran. Most programs yield an exit code of zero if they completed successfully.

Each thread retains its own value of ErrorLevel, meaning that if the current thread is interrupted by another, when the original thread is resumed it will still have its original value of ErrorLevel, not the ErrorLevel that may have been set by the interrupting thread.

Note: Since some commands set ErrorLevel to values higher than 1, it is best not check whether ErrorLevel is 1, but instead whether ErrorLevel is not zero.

The following list contains all commands, functions and GUI/Control events which set ErrorLevel, including the possible ErrorLevel values:

Language element ErrorLevel values
ClipWait0, 1
Control0, 1
ControlClick0, 1
ControlFocus0, 1
ControlGet0, 1
ControlGetFocus0, 1
ControlGetText0, 1
ControlMove0, 1
ControlSend / ControlSendRaw0, 1
ControlSetText0, 1
DllCall()0, -1, -2, -3, -4, n, An
Drive0, 1
DriveGet0, 1
EnvSet0, 1
EnvUpdate0, 1
FileAppend0, 1
FileCopy0, n
FileCopyDir0, 1
FileCreateDir0, 1
FileCreateShortcut0, 1
FileDelete0, n
FileGetAttrib0, 1
FileGetShortcut0, 1
FileGetSize0, 1
FileGetTime0, 1
FileGetVersion0, 1
FileInstall0, 1
FileMove0, n
FileMoveDir0, 1
FileRead0, 1
FileReadLine0, 1
FileRecycle0, 1
FileRecycleEmpty0, 1
FileRemoveDir0, 1
FileSelectFile0, 1
FileSelectFolder0, 1
FileSetAttrib0, n
FileSetTime0, 1
GroupActivate0, 1
Gui: GuiSize event0, 1, 2
Gui: GuiDropFiles event0, n
GuiControl0, 1
GuiControlGet0, 1
Gui control: Link click eventstring
Gui control: Custom event0, n
Gui control: ListView item change eventsubset of "SsFfCc"
Hotkey0, 1, 2, 3, 4, 5, 6, 98, 99
ImageSearch0, 1, 2
IniDelete0, 1
IniWrite0, 1
Input0, 1, NewInput, Max, Timeout, Match, EndKey:Name
InputBox0, 1, 2
KeyWait0, 1
Menu0, 1
PixelGetColor0, 1
PixelSearch0, 1, 2
PostMessage0, 1
Process0, PID
RegDelete0, 1
RegExMatch()0, string, -n
RegExReplace()0, string, -n
RegRead0, 1
RegWrite0, 1
Run0, ERROR
RunWaitn, ERROR
SendMessageFAIL, n
SetWorkingDir0, 1
Sort: U option0, n
SoundGet0, string
SoundGetWaveVolume0, 1
SoundPlay0, 1
SoundSet0, string
SoundSetWaveVolume0, 1
StatusBarGetText0, 1
StatusBarWait0, 1, 2
StringGetPos0, 1
StringReplace0, 1, n
UrlDownloadToFile0, 1
WinGetText0, 1
WinMenuSelectItem0, 1
WinSet Style/ExStyle/Region0, 1
WinWait0, 1
WinWaitActive / WinWaitNotActive0, 1
WinWaitClose0, 1

Examples

Waits a maximum of 1 second until MyWindow exists. If WinWait times out, ErrorLevel is set to 1, otherwise to 0.

WinWait, MyWindow,, 1
if ErrorLevel   ; i.e. it's not blank or zero.
    MsgBox, The window does not exist.
else
    MsgBox, The window exists.