The Ultimate Guide to Adding a Time Delay to a Batch File

time delay

This article teaches you how to prevent a batch file from running immediately after it is opened. There are various commands you can use to delay the batch file based on your need. Keep in mind that you should have a pretty good grasp of this before attempting to delay their execution.

Open Start

Click on the Windows logo on the bottom left. If you have a batch file that you want to delay running, right-click it and then click Edit to open the file in Notepad. You can skip the next two steps.

Open Notepad.

Type notepad to search for Notepad , then click Notepad at the top of the Start window.

Create your batch file.

Enter the text of your batch file, often beginning with the @echo off command.

Determine how you want to delay the batch file.

There are three main commands you can use to do this: PAUSE — Pauses the batch file until a standard key such as B. the space bar is pressed. TIMEOUT — Causes the batch file to wait a specified number of seconds or until a key is pressed before continuing. PING — Pauses the batch file until it receives a ping from a specified computer address. This usually results in only a small delay when pinging a working address.

Choose a location to delay the file.

You can defer a batch file at any point in the code, e.g. B. after the “Exit” command if you use that. Scroll down until you find the spot where you want to add the delay, then make room between the delay point and the code after it.

Type in your command.

Depending on your preferred command, do one of the following: PAUSE — Type pause on the line. You don’t have to add anything else here. TIMEOUT — Type in timeout time, replacing “time” with the number of seconds to delay. If you e.g. For example, entering timeout 30 will delay the execution of your batch file by 30 seconds. If you want to prevent people from skipping the delay with a keypress, type timeout time /nobreak (again, where “time” is the number of seconds to delay). PING — Type in ping address, where “address” is the IP address of a computer or website you want to ping.

Save your document as a batch file.

If you haven’t already saved your document as a batch file, then do the following: Click File and then Save As . Type in the name of the file followed by .bat (e.g. “My Batch File” would become “My Batch File.bat”). Click the “Save as type” drop-down box, then click All files. Choose a save location, then click Save.

Tips

You can run your batch file on any PC by double-clicking on it. The “PAUSE” command is best used in situations where you rely on a trigger to start the next section of the batch file, while the “TIMEOUT” command is best used in situations where you want the file to run automatically want to allow.

Warnings

The previously used “SLEEP” command does not work on Windows 10. Batch files don’t work on a Mac.

 

Lillie Byrd

Lillie Byrd is a saving expert for Usevoucher. He has been a newspaper reporter and editor, authored a personal finance book in 2012. She previously was a reporter at Digital Journal, covering consumer products, society, and other business topics. She also has a certificate in finance from Boston University.