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?
Stop service In order to stop the service via batch script: Open cmd as administrator. Run this command: NET STOP <SERVICE_NAME>
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.
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.
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.
You can use NET stop
, which is synchronous, i.e it will wait until the service stops.
See - NET stop
sc stop webdriveservice :loop sc query webdriveservice | find "STOPPED" if errorlevel 1 ( timeout 1 goto loop )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With