Exit codes in Windows can be broadly categorized into two types:
In the seemingly sterile output of a command-line program—a lone integer returned to the operating system—lies a sophisticated, often misunderstood contract between a process and its caller. On Windows, this integer is the (or "return code"), and while the convention 0 for success and non-zero for failure is universal, the depth beneath is uniquely shaped by Windows' architecture, its legacy subsystems, and the perils of cross-platform assumptions.
Copying assets... Done. Verifying integrity... Done. Launching legacy_setup.exe...
"Come on," Elias whispered, eyes scanning the PowerShell console. "You had one job." exit codes windows
PowerShell-native commands return rich objects, not exit codes. When you run an external .exe , PowerShell captures its exit code in $LASTEXITCODE , but the PowerShell process's own exit code is set only by exit $n . A script that runs non-existent.exe will see $LASTEXITCODE = 0xC0000135 (STATUS_DLL_NOT_FOUND), but the PowerShell process itself exits with 0 unless you explicitly forward it.
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.
Elias opened his script. He didn't need to reboot the machine immediately; he just needed to schedule it. Exit codes in Windows can be broadly categorized
Then, silence. The cursor blinked once, twice. A pause. Then, the dreaded blue screen flickered for a microsecond, and the machine rebooted.
The Windows exit code is not a bug or a relic—it is a compact, overloaded, but ultimately rich signal. It carries the legacy of three distinct error-reporting systems (Win32, NT, COM), the quirks of command-line shells, and the silent assumptions of every language runtime. Mastering it means moving from the shallow "0 vs non-zero" view to a forensic reading of the 32-bit integer as a witness to the process's final moments. In that sense, the exit code is the epitaph of every Windows program—terse, honest, and waiting to be read correctly.
ERROR_OUTOFMEMORY. 14 (0xE) Not enough storage is available to complete this operation. ERROR_INVALID_DRIVE. 15 (0xF) The system c... Microsoft Learn Show all Code (Decimal) Meaning Typical Cause 0 Success The operation completed without errors. 1 Incorrect function Unrecognized command or invalid operation attempted. 2 File not found The system cannot find the file specified at the given path. 3 Path not found The specified folder structure or path does not exist. 5 Access denied The user lacks the necessary permissions for the resource. 14 Out of memory Insufficient storage/RAM to complete the operation. 259 Still active The process is still running; this is often a "pending" status. 1603 Fatal error Frequently seen in Windows Installer (MSI) failures. Advanced & Crash Codes When a process crashes due to an unhandled exception, Windows often returns a large hexadecimal-based code: WordPress.com 0xC0000005 Launching legacy_setup
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.
But Elias’s script was looking for a binary outcome. It saw 0 as "Good" and anything else as "Bad/Reboot." The script was treating a request ("Please reboot later") as a failure condition, triggering an immediate, forced restart while other processes were still writing logs.