Exit Codes Windows -

This overlap is a trap: an exit code of 2 could mean "invalid parameter" (application-defined), or it could mean ERROR_FILE_NOT_FOUND from a failed CreateFile . Without the program's documentation, you cannot disambiguate. Three common scenarios produce exit codes that are technically correct but semantically useless:

This layering leads to a key insight: . The default for a thread is STATUS_THREAD_TERMINATED (0x00000100); for a process, it is STATUS_PENDING (0x00000103) until termination, then the final code. 2. The Semantic Wasteland: What Does Non-Zero Mean? Unlike Unix, where exit codes are small (0–255) and often mapped to sysexits.h conventions, Windows exit codes are full 32-bit values, blending several distinct categories: exit codes windows

> err 0xC0000005 # for hex 0xc0000005 / decimal -1073741819 STATUS_ACCESS_VIOLATION Check against Win32 error codes: This overlap is a trap: an exit code

| Category | Range (Hex) | Example | Meaning | |----------|-------------|---------|---------| | | 0x00000000–0x0000FFFF | 1 , 2 | Custom error (e.g., invalid input) | | Win32 Error Codes | 0x00000000–0x0000FFFF (overlap!) | ERROR_FILE_NOT_FOUND (2) | System API failure | | NTSTATUS Codes | 0xC0000000–0xFFFFFFFF | 0xC0000005 | Access violation (structured exception) | | HRESULT | 0x80070000–0x8007FFFF | 0x80070002 | COM error, wraps Win32 error 2 | Unlike Unix, where exit codes are small (0–255)

In cmd.exe , the exit code of a batch file is the exit code of the last command executed . A batch file that copies a file and then echoes a message will return 0 even if the copy failed, because echo always succeeds. This forces developers to use exit /b %errorlevel% explicitly.