Halt batch file until service stop is complete?
You can use NET stop
, which is synchronous, i.e it will wait until the service stops.
See - NET stop
sc stop webdriveservice
:loop
sc query webdriveservice | find "STOPPED"
if errorlevel 1 (
timeout 1
goto loop
)
Another version with a repetition count limit:
sc stop webdriveservice
set count=1
set limit=10
:loop
sc query webdriveservice | find "STOPPED"
if errorlevel 1 (
timeout 1
set /a count += 1
if %count% lss %limit% goto loop
)