Wait For Service To Stop in a Batch File

Sometimes in a batch file we need to wait until a service is stopped before we carry on 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