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.
It was a simple integer, a single 32-bit number passed from one process to another. But in the dark, silent logic of the operating system, that number was the difference between a functioning system and a broken loop. It was the difference between Success and Failure .
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. exit codes windows
| Exit Code | Description | Command Prompt | PowerShell | | --- | --- | --- | --- | | 0 | Successful execution | echo %errorlevel% | $LASTEXITCODE | | 1 | General errors | echo %errorlevel% | $LASTEXITCODE |
Then, silence. The cursor blinked once, twice. A pause. Then, the dreaded blue screen flickered for a microsecond, and the machine rebooted. But Elias’s script was looking for a binary outcome
If your main() throws an uncaught C++ exception, the CRT catches it, calls terminate() , and then ExitProcess(3) . The code 3 means nothing about your logic—it simply signals "CRT abnormal termination."
The installer wasn't failing. It was succeeding so hard that it demanded a reboot. But in the dark, silent logic of the
"So why," Elias muttered, hovering his cursor over the variable $LASTEXITCODE , "are you lying to me?"
These are STILL_ACTIVE (thread) and STATUS_PENDING (process). Seeing them from GetExitCodeProcess means you called it before the process actually exited. This is a classic race.
Elias was a Senior DevOps Engineer, and tonight, he was fighting a war of attrition against "IronClad," the company’s flagship deployment automation system. IronClad was supposed to be the future of their infrastructure—self-healing, autonomous, and relentless. Tonight, however, it was dumb as a bag of hammers.
He looked at the clock. 3:45 AM. He packed his bag, turned off the monitor, and walked out into the hallway.