I have four Windows services which start up automatically when the machine starts. Thereafter, I want to restart those services every 8 hours in a particular order.

e.g. Stop s1,s2,s3,s4 and than restart them in some other order like s4,s3,s2,s1. The condition is that I should wait for each service to stop completely before I stop another one.

I would want to write a .BAT or some script. Is it possible to define a scheduled task for 8 hours? This is not there in Advanced tasks. Can I do it using Windows Task Scheduler?

  • 1
    Out of curiosity, why do you want to restart the services? – mfinni Jun 30 '11 at 10:50
  • They all get hung after running for almost 12-14 hours. 8 hours is a logical point of start for the new shift to work. We are working on getting this fixed. – Geek Jun 30 '11 at 18:54

In a batch file:

net stop service4
net stop service3
net stop service2

net start service2
net start service3
net start service4

Assuming you are using xp/2003 or above you could create a scheduled task to run the batch file. Assuming you want to repeat the task every 8 hours, pick a time for it to run, then on the properties of the scheduled task, schedule tab > advanced... > repeat task. Change it to repeat every 8 hours.

| improve this answer | |
  • +1. It doesn't get any easier than this. – joeqwerty Jun 30 '11 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.