I have a pesky software service that fails every few weeks. It has two components. Service A and Service B. Service B gets in a weird state and stops accepting connections from Service A. The only way out is to restart both services manually, or reboot the server.

I would like to schedule a service restart for A and B on a regular basis. Say every 24 hours. How to go about it?

  • 3
    Scheduled task to launch a script? sc stop servicename and sc start servicename No? Feb 25 '15 at 14:05
  • 2
    Or run it locally, Net stop "serviceA" && Net start "serviceB" ; but I think the important part is, having to stop and restart a service is not a great solution for anything! Feb 25 '15 at 15:13

Following the suggestions in the comments, I ended up creating a batch file containing the proper restart sequence with timeouts. Timeouts were necessary because of the dependencies between the services. I scheduled it to run as admin every night at 4AM using the task scheduler.

net stop "Service B"
net stop "Service A"
timeout /T 10
net start "Service B"
timeout /T 10
net start "Service A"

It's not ideal, but it will do for this scenario — a remote desktop deployment with less than 10 users.


Instead of creating a bat file, which can become corrupt or missing, you can create a scheduled task with multiple actions. One action to stop the service, and another one to restart the service. Both executed with the NET command. Give them a STOP and START argument, followed by the service name.

NET STOP "Service A" 
NET START "Service A"

Here's a post on StackOverflow explaining how.


Net Stop "ServiceName" && Net Start "ServiceName"

And you can chain together && for Stop/Start ServiceB

Net Stop "ServiceA" && Net Start "ServiceA" && Net Stop "ServiceB" && Net Start "ServiceB"


You can make a bat file and inside the bat try something like this:

net stop {serviceName} & net start {serviceName}

and use the bat file as a program for a scheduled task.

  • You need two ampersands in the string above.
    – SturdyErde
    May 23 '16 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.