Kae Travis

Wait For a Service To Stop in a Batch File

Tags:

Sometimes in a batch file we need to wait for a service to stop in a batch file before we continue to processing our script.  NET STOP will only wait a finite amount of time for a service to stop, so for services that take a while to stop we can use a simple loop.  This is just an example of stopping the Adobe update service and waiting – just replace the service name as required:

@echo off

REM Run your command line here - probably: NET STOP AdobeARMservice 
 
REM Wait for Adobe Update service to stop
:LOOP
sc query AdobeARMservice | find "STOPPED" >nul 2>&1

IF ERRORLEVEL 1 (
  Timeout /T 5 /Nobreak
  GOTO LOOP
) ELSE (
  GOTO CONTINUE
)
 
:CONTINUE
 
REM Carry on with more logic

 

Wait For a Service To Stop in a Batch File
Wait For a Service To Stop in a Batch File

Leave a Reply