Discussion Locked

Setting the errorlevel?

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I need to reset the errorlevel in a DOS batch file to return a 0 (zero) on exit. Anybody know an easy way to do that?

Thanks,

Russell

5 replies

by jesalyer

ZDNet published a utility several years ago that does that. DCH1.01 and Enquire v2.7 are both available there and both should do what you want.

jeff s
spanish support analyst

by rejohnson

Unfortunately, both utilities require keyboard input to set the errorlevel accordingly. I want to set it within the batch file (e.g., set errorlevel = 0)

Thanks anyway.

by guy

Is this what you are looking for? Technet even includes DOS stuff! Technet ref Q57658

If you are writing a program that is going to be invoked from within an MS-DOS
batch file that uses the IF ERRORLEVEL command, you can use Interrupt 21H
Function 4CH, "Terminate Process with Return Code" to set the errorlevel in your
program. This function terminates the program and returns the errorlevel to the
parent process, which in this case is COMMAND.COM running the batch file.

The parametersfor Interrupt 21H, Function 4CH are AH = 4CH, AL = errorlevel,
followed by a call to Interrupt 21H. The errorlevel can be any value in the
range 0 to 255 (0 to FF, hexadecimal).

by tchieng

The easiest way to do it is simply write a utility program in Pascal and include that program in the batch file.

program Seterror;
begin
halt(0);
end.

You can even do it in C. Don't have a compiler? I can email it to you if you need it...

This discussion is closed to new replies.