Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Halt batch file until service stop is complete?

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 batch file proceeds while the service is stopping (the stop argument to sc seems only to request the stop -- it doesn't wait for the stop).

How can I modify the batch file to not proceed until the stop is complete?

like image 395
lance Avatar asked May 20 '10 14:05

lance


People also ask

How do you stop a service in a batch file?

Stop service In order to stop the service via batch script: Open cmd as administrator. Run this command: NET STOP <SERVICE_NAME>

What is @echo off batch?

batch-file Echo @Echo off @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.

How do I pause a batch script?

Execution of a batch script can also be paused by pressing CTRL-S (or the Pause|Break key) on the keyboard, this also works for pausing a single command such as a long DIR /s listing. Pressing any key will resume the operation. Pause is often used at the end of a script to give the user time to read some output text.

How do I pause a few seconds in a batch file?

Type in your command.TIMEOUT — Type timeout time where "time" is replaced by the number of seconds to delay. For example, typing in timeout 30 will delay your batch file for 30 seconds.


2 Answers

You can use NET stop, which is synchronous, i.e it will wait until the service stops.

See - NET stop

like image 165
mdma Avatar answered Sep 28 '22 13:09

mdma


sc stop webdriveservice :loop sc query webdriveservice | find "STOPPED" if errorlevel 1 (   timeout 1   goto loop ) 
like image 29
js2010 Avatar answered Sep 28 '22 13:09

js2010