Skip navigation

How can I configure a program/batch file to run every x minutes?

A. A. NT comes with a powerful built in scheduling tool, the at command, however it is not really suitable for running a command every 5 minutes, to do this you would have to submit hundreds of at jobs to run at certain times of the day. There are a number of tools supplied with the Windows NT Resource Kit which will help.

The first is called sleep.exe, and is user to set a command file to wait for n seconds (like the timeout command), and its usage is simply
sleep 300
which would make the batch file pause for 5 minutes, so if you wanted a command file/program to run every 5 minutes you could write a batch file with the following (name run5.bat)
<program name>
sleep 300

There are a number of problems with this approach, the command session has to stay open, and the 5 minutes does not start until the program has closed (however this can be solved by running the program in a separate thread by putting the word "start" in front of the program, e.g. start <program>).

Another program is called SOON.EXE and this schedules a task to run in n seconds from now, to use soon the scheduler service has to be running (start - settings - control panel - services). Again you could create a batch file to use it (runsoon.cmd)
soon 300 runsoon.cmd

Run the command file using the at command or soon, e.g. from the command line
soon 300 runsoon.cmd
to get it started

Once the SOON is scheduled to run, if you wanted to stop it you would use the AT command to get a list of current scheduled jobs

Status ID Day Time Command Line -------------------------------------------------------------------------------
0 Today 9:04 AM runsoon.cmd

Once its ID is known it can be stopped using

C:\>at \[\\computer name\] <ID> /delete
e.g. C:\>at 0 /delete

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.