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

John Savill

March 4, 1999

2 Min Read
ITPro Today logo in a gray background | ITPro Today

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)

sleep 300
run5

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

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
notepad.exe
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

C:>at
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] /delete
e.g. C:>at 0 /delete

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like