I\'m using a batch file to stop a Windows service. I\'m using the sc command, but I\'m open to other ideas, given the question below. The problem is that the
I had a similar issue with net stop. It returns when the service is indeed stopped, but the executable may still be running.
For upgrade reasons, this is not good enough, we need to wait until the process has finished.
I've used a simple loop to wait until the service executable has actually finished:
net stop "ServiceName"
:loop1
set _CmdResult=""
for /f "tokens=1" %%a in ('TASKLIST ^| FINDSTR ServiceName.exe') do set _CmdResult=%%a
if not %_CmdResult% == "" (
timeout 5
goto loop1
)
Once the the executable finishes, the loop will break.