How to Delay Batch File: 7 Steps (with Pictures)

Table of contents:

How to Delay Batch File: 7 Steps (with Pictures)
How to Delay Batch File: 7 Steps (with Pictures)

Video: How to Delay Batch File: 7 Steps (with Pictures)

Video: How to Delay Batch File: 7 Steps (with Pictures)
Video: 3 Ways to Remove or Change the Administrator Password in Windows 10 2024, December
Anonim

This wikiHow teaches you how to prevent batch files from running immediately after opening. There are several commands you can use to delay the running of a batch file, depending on your needs. Remember, you must have sufficient knowledge of writing batch files before attempting to delay.

Step

Delay a Batch File Step 1
Delay a Batch File Step 1

Step 1. Go to Start

Windowsstart
Windowsstart

Do this by clicking on the Windows logo in the lower-left corner.

If you already have a batch file that you want to defer, right-click the file, then click Edit to open the file in Notepad. By doing this, you can skip the next two steps.

Delay a Batch File Step 2
Delay a Batch File Step 2

Step 2. Launch Notepad

Type notepad into Start, then click Notepad displayed at the top of the Start window.

Delay a Batch File Step 3
Delay a Batch File Step 3

Step 3. Create a batch file

This file often starts with the command

@echo off

. After you have written the command, enter the batch file text as needed.

Step 4. Specify how you want to delay files

There are three main commands that can be used to delay batch files:

  • PAUSE - The batch file will be paused until a standard key (eg Spacebar) is pressed.
  • TIMEOUT - The batch file will pause for a few seconds (or when a key is pressed) before running again.
  • PING - The batch file will be paused until it receives a pingback from the specified computer address. Usually the file will only pause if you ping a working address.
Delay a Batch File Step 5
Delay a Batch File Step 5

Step 5. Decide where to suspend the file

You can suspend the batch file at any point in the code (save after the " Exit " command if you use one). Scroll down the screen until you find the point where you want to delay the batch file, then make some space between the code before the delay point and the code after it.

Delay a Batch File Step 6
Delay a Batch File Step 6

Step 6. Type in the command

Depending on the command selected, perform one of the following commands:

  • PAUSE - Type pause into the line. Don't add anything here.
  • TIMEOUT - Type the timeout time. Replace " time " with the number of seconds to delay the file. For example, if you want to delay the batch file for 30 seconds, type timeout 30.

    To prevent others from skipping the delay at the push of a button, type timeout time /nobreak (replace " time " with the number of seconds of the delay)

  • PING - Type in the ping address. Replace "address" with the IP address of the computer or site you want to PING.
Delay a Batch File Step 7
Delay a Batch File Step 7

Step 7. Save the document as a batch file

If the document is not already saved as a batch file, do the following:

  • Click File, then select Save As….
  • Type in the file name followed by a.bat extension (eg "My Batch File" will change to "My Batch File.bat").
  • Click the "Save as type" drop-down box, then click All Files.
  • Specify the storage location, then click Save.

Tips

  • You can run the batch file in any Windows by double-clicking it.
  • The " PAUSE " command is best used when you want the user to run the next part of the batch file. The " TIMEOUT " command is perfect for when you want the file to run itself automatically.

Warning

  • The old "SLEEP" command doesn't work on Windows 10.
  • The batch file cannot be run on a Mac computer.

Recommended: