Strange %ERRORLEVEL% Behavior [SOLVED]
Posted: 20 Aug 2021 11:37
I'm sure it is something wrong with my script
but, I am seeing some strange behavior with checking the %ERRORLEVEL% when I attempt to check the firewall status using the netsh command:
All I see on the console is:
pause 1>nul
If I remove the quotes in front of fRules, I get the following:
ON"
I have also tried IF %ERRORLEVEL% EQU 0 and the negation with IF %ERRORLEVEL% NEQ 0 to no avail. I would appreciate any advice.

Code: Select all
@echo off
setlocal enabledelayedexpansion
netsh advfirewall show currentprofile |findstr /i "State" |findstr /i "ON" >nul
if "%ERRORLEVEL%"=="0" (
set "fRules=ON"
) else (
set "fRules=OFF"
)
echo %fRules%
pause > nul
pause 1>nul
If I remove the quotes in front of fRules, I get the following:
ON"
I have also tried IF %ERRORLEVEL% EQU 0 and the negation with IF %ERRORLEVEL% NEQ 0 to no avail. I would appreciate any advice.