Environment variables belong to the current "process" so they can't be changed from outside. Provided you check the error level after the relevant command in your batch file, you should be checking the right value.
You can confirm this by opening up two command windows and entering into the first:
c:> set errorlevel=7
and then the second:
c:> set errorlevel=9
then go back to the first and:
c:> echo %errorlevel%
7
You should be very careful about setting the `errorlevel` environment variable by the way. That particular variable is a special one in that, when you haven't set it specifically, it will automatically serve up the return code from the previous program.
Setting it explicitly overrides this behaviour, and the only way to recover is to either use `if errorlevel N`<sup>(a)</sup> instead of the environment variable (it bypasses the environment variable), or use `set errorlevel=` to remove the override.
---
<sup>(a)</sup> The correct way to do this is mandated by fact that the `errorlevel` expression is true if the error level is *greater than or equal to* the value specified. Because of that, you should do it in reverse order, something like:
if errorlevel 3 goto :got3ormore
if errorlevel 2 goto :got2
if errorlevel 1 goto :got1
if errorlevel 0 goto :got0
goto :gotnegative