64

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?

Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85

1 Answers1

135

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.

Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
  • 19
    Excellent tip! Depending on the service, I sometimes add a `timeout /T 3` (where 3 is a # of seconds) in between the stop & start. – NateJ Jul 05 '17 at 20:19
  • 7
    FYI the Service Name of "Print Spooler" is just "Spooler". "Print Spooler" is the Display Name. – TylerH Nov 15 '17 at 17:23
  • 1
    @NateJ `timeout` appears to have no affect whatsoever. I've tried intervals from 10 to as high as 120 and the restart is still instant. I suspect it's run in parallel and the start is only sequential because it's queued by the service stopping. – JoelAZ May 29 '18 at 05:53
  • Good tip @Kurt Van den Branden! And @NateJ your timeout tip likewise which worked for me on a Win2016 Server. I added `timeout /T 3 /NOBREAK` just for saftey sake. – Lars Nov 12 '19 at 10:44
  • 17
    You can also use a single action like `powershell -command "Restart-Service Spooler"` – Marc8 Sep 16 '20 at 15:58