35

In my windows, I want to schedule a windows service to start once every 10 seconds. I tried using the windows task scheduler but it only gives me an option to repeat the service daily, weekly and monthly.

Is there a way I can schedule the windows service to start once every 10 seconds using windows task scheduler?

What could be done?

4 Answers4

55

A Windows Task Scheduler trigger cannot repeat more often than every 1 minute, but you can set up multiple triggers. To run a task every 10 seconds, add six Triggers. Each one should run the task Daily, and Repeat task every 1 minute. Their start times should be 12:00:00 AM, 12:00:10 AM, 12:00:20 AM, 12:00:30 AM, 12:00:40 AM, and 12:00:50 AM.

Edit Trigger dialog

Silly, but it works.

Adam C
  • 918
  • 8
  • 8
5

It's silly windows doesn't have this functionality built into Task Scheduler. However, it can be easily worked around with a simple powershell script.

 $i = 0
 for ($i=0; $i -le 4) 
   Start-Service -Name "servicename"  
   sleep 10
   $i++
 }

Save this as a *.ps1 file on your host. Then follow Adam C's task scheduler settings and schedule this to run every minute. This will start the service (which I named "servicename") every 10 seconds.

G_Style
  • 149
4

To do that, you should write a windows service, as that is what they are for.

soandos
  • 24,600
  • 29
  • 105
  • 136
0

You can use autohotkey

The following autohotkey solution is much better than the windows task scheduler solutions because the task scheduler solutions only work from a specific time. So if your computer were turned on after that time then you'd have to wait for the clock to reach that time. This just operates as soon as the script starts.

With autohotkey, you can use either a)a timer or b)a while true and a sleep. (Note- i've tested both.. both seem fine.. and btw the while loop with the sleep doesn't hog cpu)

Suppose your autohotkey file is blah.ahk

And the thing you want to run is a bat file.

while true
{
Run cmd /c c:\blah\blah.bat,,Hide
sleep 10000  ; 10 seconds
}

The bat file could have a list of commands. Or you could run an exe Run c:\blah\blah.exe

You can have a main autohotkeys file with include lines , one for each of the ahk scripts that you like to run. That avoids having lots of tray icons, or having one giant ahk file.

A timer version looks like this

setTimer, label, 10000     ;10 seconds
return

label: ; do some commands return

barlop
  • 25,198