There is one internal command that can set the errorlevel code, EXIT. Here
is the help text:
Quits the CMD.EXE program (command interpreter) or the current batch
script.
EXIT [/B] [exitCode]
/B specifies to exit the current batch script instead of
CMD.EXE. If executed from outside a batch script, it
will quit CMD.EXE
exitCode specifies a numeric number. if /B is specified, sets
ERRORLEVEL that number. If quitting CMD.EXE, sets the process
exit code with that number.
try creating a batch file seterror.cmd with this content:
@echo off
if "%1" EQU "" (
echo/Syntax: {call} %~n0 [errorlevelcode]
) else (
exit /b %1
)
You can then call this to set the errorlevel from within a batch script,
i.e.:
call seterror -1
call seterror 0
call seterror 123
A bit quirky, as an explicit set errorlevel={whatever} screws things up
somehow.
This does not fully fill the requirement, however, I suspect it may be of
some use.
/Al