Batch script errorlevel issue with registry key

Expansion takes place before any command is executed inside a block of code. Basically, anything placed within a group of parenthesis.

Because the errorlevel variable is already expanded before the second reg query command is executed, the result of the second reg query doesn't affect the expression of the if command that is placed within parenthesis.

Luckily, the errorlevel variable has a special feature. It can be used by the if command without expanding it.

:: This is true when %errorlevel% >= 1
if errorlevel 1 (

:: This is true when %errorlevel% <= 0
if not errorlevel 1 (