Friday, July 21, 2017

wscript exit code errorlevel 9009


The same script can end with different command box errorlevel values between cscript and wscript. The command box %errorlevel% after a wscript command will likely be 9009.  This is because the command interpreter immediately becomes ready for the next command even if the script is still running.  It is not able to receive the exit code from the wscript interpreter.  cscript on the otherhand waits for the script to exit before the command box is available again.  In that case the %errorlevel% command reflects the vbscript exit code.

echo %errorlevel%