Image

Image

Search This Blog

Sunday, April 09, 2023

Stop a service and wait for it to stop

 

@echo off
:: echo without NewLine
 <nul set /p =Please wait. Stopping Service...
 :: request stop service
sc stop "service we need to stop" >nul
:: wait up to 30 seconds for the service to stop
set a=1
set tmout=30
:retry
:: is it stopped ?
sc query "service we need to stop" | find "STOPPED"
if errorlevel 1 (
:: echo dots on the same line
 <nul set /p =.
 timeout 1 /nobreak >nul
 set /a a += 1
if %%a%% lss %%tmout%%  goto retry
)
:: allow one second to see the messages
timeout 1 /nobreak >nul

No comments:

Post a Comment

Blog Archive