Computer Hope

Other Pages

Home
Site map
Computer help

Dictionary
News
Q&A
What's new

Tools

E-mail this page
Print Preview
Edit this page




Reference number: CH000036

How to execute commands in a batch file in timed intervals.

Issue:

How to execute commands in a batch file in timed intervals.

Solution:

The solution for executing a batch file or commands in a batch file may change depending on what best fits your needs.

First solution

In the below example, the batch file is placed into a loop and executes the "dir" command every 20 seconds. This solution would be best for users who need to execute a command frequently.

:START
REM Execute the MS-DOS dir command ever 20 seconds.
dir
SLEEP 20
GOTO END

Note: In order for the above batch file to run properly you must have the sleep MS-DOS utility on the computer. This utility is not included with any version of MS-DOS or Windows. However, once downloaded will allow your computer to sleep / delay for any specified amount of seconds. See our utility download page for a download link.

Second solution

Our next solution is for users who need to execute a batch file but only need to execute the command every few hours, days, months, or years. Instead of relying on the batch file continuously running, we recommend that a user utilize a utility that will execute the batch file when the date and/or time arrives.

Microsoft Windows NT, 2000, and XP users, for example, can use the AT command to schedule timed events through MS-DOS.

Additional information:

  • If you're looking for additional information about executing a batch file at a specific time see document CH000785.

 

 

Index

Category:
Batch file help

Companies:
Microsoft

Related Pages:

Resolved

Were you able to locate the answer to your questions?

Home - Computer help - Contact - Dictionary - Links
Link to Computer Hope - Bookmark Computer Hope