banner



How To Restart A Windows Service Using Task Scheduler

Restart Windows Service at a Specific Time

  I want to restart some specific service for a specific time every week. Tin I employ the Net command?

— Shanmuga

Hi Shanmuga.

Yes. With the help of the Windows Task Scheduler, you tin utilise the Internet control to restart a specific service at a specific time.

To do so:

1. Find the name of your service

Each Windows Service has two names — a brusque service proper name and a friendly display proper name. We need the service name for the Cyberspace command.

If you don't already know the service name, or want to validate it:

  1. Launch the Windows Services application. You can find information technology by searching for "services" in the Control Console, or past running services.msc at a command prompt.

  2. Gyre to locate your service in the list:

    Windows Services application

  3. Double-click the entry to open the service's backdrop. The service proper name is displayed at the top.

Hither nosotros see that the name of the Print Spooler service is actually "Spooler":

Print Spooler service name

2. Create a batch file to restart your service

With the service name in hand, we tin can now use the Cyberspace command to restart the service.

Create a new batch file and enter the following two commands:

NET Finish "Your Service Proper noun"
Internet Kickoff "Your Service Name"

Please supervene upon 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 proper noun is "Spooler", the batch file should expect similar this:

NET End "Spooler"
Cyberspace START "Spooler"

Save the batch file to a well-known location. We'll employ information technology in the next step.

Examination the batch file

At this point, we recommend performing a quick examination to ensure that the batch file works as expected. Run it from an authoritative control prompt and ostend that it restarts your service.

3. Create a scheduled task to run the batch file at the time you wish to restart the service

At present that you are able to restart the service with the batch file, let's schedule information technology to run whenever you like.

For case, here is how we would restart the Impress Spooler service every Sunday at one AM:

  1. Open the Windows Task Scheduler. You showtime it from the Control Console or past running taskschd.msc from a command prompt.

  2. Click Create Basic Job on the right:

    Task Scheduler: Create Basic Task

    The Create Basic Task Wizard window volition come.

  3. Give the job a descriptive name:

    Enter the task name

    Click Side by side to continue.

  4. Select Weekly and click Next:

    Set the task to run weekly

  5. Set the day and time to restart the service:

    Set the day and time to restart the service

    Click Next to go on.

  6. Ensure that the action is Beginning a program and motion to the next step:

    Set the action - Start a program

  7. Enter the full path to the batch file you created to restart the service:

    Specify the batch file to restart the service

    Click Next to proceed.

  8. Review the summary and brand sure that everything looks good.

    Check the Open the Properties dialog… box at the bottom considering nosotros'll demand to adjust one of the tasks properties:

    Review the summary of the task

    Click Finish.

  9. 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.

    Run the task with highest privileges

    Click OK to save your settings.

Going forrard, the new task will come alive at the scheduled time to promptly restart the service. You should be good to go.

Improvement: Utilise ServicePilot instead of NET for better reliability

Use ServicePilot instead of NET.EXE

While Cyberspace.EXE volition work for most situations, there are a few scenarios where it may fall short.

Does your service:

  • accept longer than 30 seconds to shut down?
  • occasionally hang and refuse to stop?

If so, the NET Terminate command may fail. And when that happens, the subsequent telephone call to Cyberspace START volition fail also (because the service volition non exist idle). The finish result is that your service will be left in an unusable/unresponsive state!

Our free ServicePilot utility was congenital to piece of 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:

  1. Download ServicePilot from our website. Salve the executable in a well-known location (e.g. C:\Apps\ServicePilot\ServicePilot.exe).

  2. Edit the batch file y'all created to restart the service.

  3. Delete the ii NET lines.

  4. Add together 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 -await 300 parameter instructs ServicePilot to wait up to 300 seconds (5 minutes) for the service to terminate and restart. Experience gratis to increment (or subtract) the timeout based your specific use case.

  5. Salve the batch file.

Equally you did with the NET version, delight perform a quick test to ensure that the updated batch file works as expected. Launch information technology from an administrative command prompt and confirm that it restarts your service.

Best of luck with your service!

You may also like...

Source: https://www.coretechnologies.com/blog/windows-services/how-to-restart-at-specific-time/

Posted by: robeyandeavy1951.blogspot.com

0 Response to "How To Restart A Windows Service Using Task Scheduler"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel