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:
ClipWait | 0, 1 |
Control | 0, 1 |
ControlClick | 0, 1 |
ControlFocus | 0, 1 |
ControlGet | 0, 1 |
ControlGetFocus | 0, 1 |
ControlGetText | 0, 1 |
ControlMove | 0, 1 |
ControlSend / ControlSendRaw | 0, 1 |
ControlSetText | 0, 1 |
DllCall() | 0, -1, -2, -3, -4, n, An |
Drive | 0, 1 |
DriveGet | 0, 1 |
EnvSet | 0, 1 |
EnvUpdate | 0, 1 |
FileAppend | 0, 1 |
FileCopy | 0, n |
FileCopyDir | 0, 1 |
FileCreateDir | 0, 1 |
FileCreateShortcut | 0, 1 |
FileDelete | 0, n |
FileGetAttrib | 0, 1 |
FileGetShortcut | 0, 1 |
FileGetSize | 0, 1 |
FileGetTime | 0, 1 |
FileGetVersion | 0, 1 |
FileInstall | 0, 1 |
FileMove | 0, n |
FileMoveDir | 0, 1 |
FileRead | 0, 1 |
FileReadLine | 0, 1 |
FileRecycle | 0, 1 |
FileRecycleEmpty | 0, 1 |
FileRemoveDir | 0, 1 |
FileSelectFile | 0, 1 |
FileSelectFolder | 0, 1 |
FileSetAttrib | 0, n |
FileSetTime | 0, 1 |
GroupActivate | 0, 1 |
Gui: GuiSize event | 0, 1, 2 |
Gui: GuiDropFiles event | 0, n |
GuiControl | 0, 1 |
GuiControlGet | 0, 1 |
Gui control: Link click event | string |
Gui control: Custom event | 0, n |
Gui control: ListView item change event | subset of "SsFfCc" |
Hotkey | 0, 1, 2, 3, 4, 5, 6, 98, 99 |
ImageSearch | 0, 1, 2 |
IniDelete | 0, 1 |
IniWrite | 0, 1 |
Input | 0, 1, NewInput, Max, Timeout, Match, EndKey:Name |
InputBox | 0, 1, 2 |
KeyWait | 0, 1 |
Menu | 0, 1 |
PixelGetColor | 0, 1 |
PixelSearch | 0, 1, 2 |
PostMessage | 0, 1 |
Process | 0, PID |
RegDelete | 0, 1 |
RegExMatch() | 0, string, -n |
RegExReplace() | 0, string, -n |
RegRead | 0, 1 |
RegWrite | 0, 1 |
Run | 0, ERROR |
RunWait | n, ERROR |
SendMessage | FAIL, n |
SetWorkingDir | 0, 1 |
Sort: U option | 0, n |
SoundGet | 0, string |
SoundGetWaveVolume | 0, 1 |
SoundPlay | 0, 1 |
SoundSet | 0, string |
SoundSetWaveVolume | 0, 1 |
StatusBarGetText | 0, 1 |
StatusBarWait | 0, 1, 2 |
StringGetPos | 0, 1 |
StringReplace | 0, 1, n |
UrlDownloadToFile | 0, 1 |
WinGetText | 0, 1 |
WinMenuSelectItem | 0, 1 |
WinSet Style/ExStyle/Region | 0, 1 |
WinWait | 0, 1 |
WinWaitActive / WinWaitNotActive | 0, 1 |
WinWaitClose | 0, 1 |
Example
WinWait, MyWindow, , 1
if ErrorLevel ; i.e. it's not blank or zero.
MsgBox, The window does not exist.
else
MsgBox, The window exists.