How to restart a windows service using Task Scheduler

WindowsServiceScheduled Tasks

Windows Problem Overview


The easiest way to do this is to create a batch file with:

NET stop <service name>
NET start <service name>

Once the batch file is created and tested, add it to Windows Task Scheduler and run it at a specific time interval. Problem here is, when the bat file is missing or corrupt, the service won't restart. So, are there other ways to restart a service at a specific time interval?

Windows Solutions


Solution 1 - Windows

Instead of using a bat file, you can simply create a Scheduled Task. Most of the time you define just one action. In this case, create two actions with the NET command. The first one to stop the service, the second one to start the service. Give them a STOP and START argument, followed by the service name.

In this example we restart the Printer Spooler service.

NET STOP "Print Spooler" 
NET START "Print Spooler"

enter image description here

enter image description here

Note: unfortunately NET RESTART <service name> does not exist.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKurt Van den BrandenView Question on Stackoverflow
Solution 1 - WindowsKurt Van den BrandenView Answer on Stackoverflow