if statement - Nested If-Else in batch command -


i trying check if 2 services present or not. if either 1 not present should print "no" else print "yes". tried is:

@echo off set service1=present_service set service2=not_present  sc query %service1% | find "does not exist" >nul if %errorlevel% equ 1 (     sc query %service2% | find "does not exist" >nul     if %errorlevel% equ 1 (       echo yes     ) else (       echo no     )     ) else ( echo no ) 

if check single one, works fine. here %errorlevel% not changing value in second case. if service2 not present, prints yes. can on this.

try this;

@echo off setlocal enabledelayedexpansion set service1=present_service set service2=not_present  sc query %service1% | find "does not exist" >nul if %errorlevel% equ 1 (     sc query !service2! | find "does not exist" >nul     if !errorlevel! equ 1 (       echo yes     ) else (       echo no     )     ) else ( echo no ) 

this problem delayed expansion


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -