Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a scheduled task that runs a batch file, and even though I can see the results of it completing successfully, according to the task scheduler it fails with error 0xff, every time.

I have other batch files scheduled that also complete successfully and return 0x0 as they should. The only difference I can see between these files is that the working ones end with:

    ("notify me" script here)

whereas the broken one ends with:

IF %2==something (
    (run a program here)
        (same "notify me" script here)

Does an IF block return 0xff if false or something? What's the deal?

share|improve this question
up vote 5 down vote accepted

The syntax you're looking for is:

IF "%2"=="SOMETHING" (

When %2 is empty, the line you have becomes:


That's invalid syntax. Putting the quotes in it makes it:


That's valid.

share|improve this answer
Perfect. Thanks! – Kev Sep 21 '09 at 14:08
Remember! exit 0xFF means "syntax error in batch file"! – BobHy Jan 27 at 15:27

After some testing, I figured out that IF blocks are okay, they don't seem to change the error level, but what was messing it up was the "%2==something"--the times that were failing, there was no second parameter being passed to the batch file. So I'm not sure how to "safely" test for whether a parameter exists (i.e., without it erroring out 0xff when it's not there) except maybe to have yet another IF ERRORLEVEL after that. But anyway, I just changed the scheduled task so it will always have a second parameter (whether it's "something" or not) and it seems to return 0x0 as it should now.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.