This article will show you how to prevent a batch file from running immediately when it is opened. There are several different commands that can be used to delay a batch file. Keep in mind that you should know well how to create batch files before trying to make it delay.
Step 1. Open the Start Menu
Click on the Windows logo in the lower left corner of the screen.
If there is a batch file ready, right-click on it and choose Edit from the menu to open the file in Notepad. Then skip the next two steps
Step 2. Open Notepad
Type notepad to find Notepad, and then click Notepad at the top of the Start menu.
Step 3. Create a batch file
First enter the command
@echo offand then enter other commands in your batch file. Step 4. Determine how to delay the launch of the batch file.
There are three main commands that can be used to delay a batch file:
- PAUSE - the batch file is paused until a standard key (such as space) is pressed.
- TIMEOUT - the batch file is paused for a specified number of seconds (or until a key is pressed).
- PING - the batch file is paused until the file receives a response from the specified computer address. This usually results in a slight delay if the work address is pinged.
Step 5. Select the place where to enter the delay command
This can be done at any point in the code (but after the "Exit" command, if you used it). Scroll down to find the point at which you want to pause the file, and then enter a space between the code before the pause point and the code after that point.
Step 6. Enter the command
Do one of the following, depending on the command you are using:
- PAUSE - just type pause on the line.
- TIMEOUT - enter timeout time, where instead of "time" substitute the time (number of seconds) of the delay. For example, if you enter timeout 30, the file will be suspended for 30 seconds.
To prevent users from canceling the delay by pressing a key, enter timeout time / nobreak (where time is the number of seconds in the delay)
- PING - enter a ping address, where instead of "address" substitute the IP address of the computer or website being pinged.
Step 7. Save the text file as a batch file
If you haven't already saved the text file as a batch file, follow these steps:
- Click File> Save As.
- Enter a file name, and then enter a.bat extension (for example, "Batch_file.bat").
- Open the Save as type menu and select All Files.
- Select a folder to save and click "Save".
- To run a batch file on Windows, just double click on it.
- Use the PAUSE command to manually resume the file (when the user presses a key), and the TIMEOUT command to automatically resume the file.
- The "SLEEP" command in Windows 10 does not work.
- Batch files do not work on Mac computers.