Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart a windows service using Task Scheduler

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?

like image 949
Kurt Van den Branden Avatar asked Mar 30 '16 12:03

Kurt Van den Branden


Video Answer


1 Answers

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.

like image 66
Kurt Van den Branden Avatar answered Sep 17 '22 04:09

Kurt Van den Branden