I am new to creating batch files in windows, I am trying to create a batch file to check the service in windows status, if the service is in running state then am trying to execute another command to check status but am not able to get the output for the second command.
Am checking the status of query by using %ERRORLEVEL%.
The following is my code in batch file :
@echo off
sc query "MpsSvc" | find "RUNNING"
echo "%ERRORLEVEL%"
if "%ERRORLEVEL%" EQU "0" (
netsh advfirewall show currentprofile state | find "ON"
if "%ERRORLEVEL%" EQU "0" (
echo firewall is already enabled
)
if "%ERRORLEVEL%" NEQ "0" (
echo going to enable firewall
)
)
if "%ERRORLEVEL%" NEQ "0" (
echo firewall service is not running
)
pause
When am trying to run my batch file am getting the %ERRORLEVEL% of the command echo firewall is already enabled only am getting for the another command echo firewall is already enabled.
Can anybody tell me what mistake I did?