To do so:
1. Find the name of your service
Each Windows Service has two names — a short service name and a friendly display name. We need the service name for the NET command.
If you don’t already know the service name, or want to validate it:
Launch the Windows Services application. You can find it by searching for “services” in the Control Panel, or by running services.msc at a command prompt.
- Scroll to locate your service in the list:
Double-click the entry to open the service’s properties. The service name is displayed at the top.
Here we see that the name of the Print Spooler service is actually “Spooler”:
2. Create a batch file to restart your service
With the service name in hand, we can now use the NET command to restart the service.
Create a new batch file and enter the following two commands:
NET START "Your Service Name"
Please replace Your Service Name with the service name identified in step 1. The quotes are required if the service name contains a space.
For example, if your service name is “Spooler”, the batch file should look like this:
NET START "Spooler"
Save the batch file to a well-known location. We’ll use it in the next step.
Test the batch file
At this point, we recommend performing a quick test to ensure that the batch file works as expected. Run it from an administrative command prompt and confirm that it restarts your service.
3. Create a scheduled task to run the batch file at the time you wish to restart the service
Now that you are able to restart the service with the batch file, let’s schedule it to run whenever you like.
For example, here is how we would restart the Print Spooler service every Sunday at 1 AM:
Open the Windows Task Scheduler. You start it from the Control Panel or by running taskschd.msc from a command prompt.
Click Create Basic Task on the right:
The Create Basic Task Wizard window will come up.
Give the task a descriptive name:
Click Next to continue.
Select Weekly and click Next:
Set the day and time to restart the service:
Click Next to continue.
Ensure that the action is Start a program and move to the next step:
Enter the full path to the batch file you created to restart the service:
Click Next to continue.
Review the summary and make sure that everything looks good.
Check the Open the Properties dialog… box at the bottom because we’ll need to adjust one of the tasks properties:
And finally, in the Properties window, check the Run with highest privileges box. The batch file must run with administrative rights so that it can restart the service.
Click OK to save your settings.
Going forward, the new task will come alive at the scheduled time to promptly restart the service. You should be good to go.
Improvement: Use ServicePilot instead of NET for better reliability
While NET.EXE will work for most situations, there are a few scenarios where it may fall short.
Does your service:
- take longer than 30 seconds to shut down?
- occasionally hang and refuse to stop?
If so, the NET STOP command may fail. And when that happens, the subsequent call to NET START will fail too (because the service will not be idle). The end result is that your service will be left in an unusable/unresponsive state!
Our free ServicePilot utility was built to work around NET’s shortcomings. It will wait for longer than 30 seconds if necessary and will do its best to forcibly terminate an unresponsive service.
To use ServicePilot instead of NET:
Download ServicePilot from our website. Save the executable in a well-known location (e.g. C:\Apps\ServicePilot\ServicePilot.exe).
Edit the batch file you created to restart the service.
Delete the two NET lines.
Add the following line (adjusting the full path to ServicePilot and your service name as necessary):C:\Apps\ServicePilot\ServicePilot.exe -restart -wait 300 "Your Service Name"
Note: The -wait 300 parameter instructs ServicePilot to wait up to 300 seconds (5 minutes) for the service to stop and restart. Feel free to increase (or decrease) the timeout based your specific use case.
Save the batch file.
As you did with the NET version, please perform a quick test to ensure that the updated batch file works as expected. Launch it from an administrative command prompt and confirm that it restarts your service.
Best of luck with your service!
UPDATE: Use our free Service Scheduler utility instead of the Task Scheduler
We got tired of manually creating batch files and scheduled tasks to control our services so we created a free application to do it all. 🙂
With Service Scheduler, you can easily start, stop or restart any Windows Service — daily, weekly or monthly at a time of your choosing:
Service Scheduler is completely free and super easy to use. You can schedule your service in seconds:
Download Service Scheduler and check it out today!