
The sleep command is not a standard Windows batch command. To make a batch file wait for a number of seconds, you can use the timeout command, which was introduced in Windows 2000. However, this command does not support fractions of seconds. To allow fractions of seconds, you can use the following command:
powershell.exe -Command Start-Sleep -MilliSeconds ( 1000 * %1)
Here, `%1` is the number of seconds (fractions allowed) for the delay, as specified on the command line.
| Characteristics | Values |
|---|---|
| Command to sleep for fractions of a second | powershell.exe -Command "Start-Sleep -MilliSeconds ( 1000 * %1) " |
| To sleep for 123 milliseconds | ping 192.0.2.1 -n 1 -w 123 >nul |
| To sleep for 50 milliseconds | powershell Start-Sleep -m 50 |
| To sleep for 5 seconds | timeout 5 |
| To sleep for 3 seconds | ping 1.1.1.1 -n 1 -w 3000 >NUL |
| To sleep for 0.5 or 0.25 seconds | ping 127.0.0.1 -n 1 -w 500> nul |
Explore related products
$20.94 $21.98
$28.49 $47.99
What You'll Learn

Using the timeout command
The timeout command is a standard feature in Windows 7 and 8 and was introduced in Windows 2000. It is used to pause the command processor for a specified number of seconds. This command is typically used in batch files.
The syntax for the command is:
Timeout /t time in seconds
For example, to pause for 5 seconds, you would use:
Timeout /t 5
The timeout command can also be used without the `/t` switch, in which case the pause duration is specified by the number following the command. For example:
Timeout 5
The timeout command can also be used to pause indefinitely by using the /nobreak switch. This will ignore any key presses except for CTRL-C. For example:
Timeout /nobreak
It is worth noting that the timeout command only works in increments of whole seconds. If you need to pause for a fraction of a second, you can use the ping command or the Sleep method in VBScript, which accepts values in milliseconds. Here is an example using the `ping` command to pause for 500 milliseconds:
Ping 127.0.0.1 -n 1 -w 500 > nul
Vb
@if (@CodeSection == @Batch) @then @echo off
Setlocal
For /L %%I in (10,-1,1) do (
Set /P "=%%I... " Call :pause 250 You may want to see also The "ping" command is a useful tool for introducing delays in batch files. It is particularly handy when dealing with fractions of a second, as it can provide more precise timing than the "timeout" command. To use the "ping" command for delaying execution, you can follow these general steps: It is important to note that while the "ping" command is versatile and works across different versions of Windows, it is not the ideal solution for introducing delays in batch files. The "timeout" command is generally preferred when it is supported by the operating system. Additionally, the "ping" command has a minimum delay of 500 milliseconds, so it may not be suitable for very short delays. Remember that when using the "ping" command in batch files, you should avoid naming your batch file with the same name as the "ping" command to prevent unexpected behaviour. Additionally, always test your batch files in a controlled environment before deploying them to ensure they function as intended. You may want to see also The Start-Sleep command is a versatile PowerShell cmdlet that allows you to pause your PowerShell session or script with precise timing control. It is particularly useful when you need to introduce a delay in your scripts or automate certain tasks that require specific timing. The basic syntax of the Start-Sleep command is straightforward: `Start-Sleep [-Seconds] Here's an explanation of the syntax: It's important to note that if you don't specify a parameter (Seconds or Milliseconds), the Start-Sleep command assumes the time value is in seconds. The Start-Sleep cmdlet also offers advanced features for more complex scripting needs. For instance, by default, Start-Sleep runs synchronously, blocking PowerShell execution until it completes. However, you can use the `-AsJob` switch to allow asynchronous operation: `Start-Sleep -Seconds 10 -AsJob` This command will execute Start-Sleep in a background PowerShell job, allowing PowerShell to continue with other tasks while the sleep timer is active. In addition to the Start-Sleep command, there are alternative methods to introduce delays in batch files, such as using the timeout command or the ping command. However, these methods may have limitations or compatibility issues with certain Windows versions. You may want to see also The VB Script can be used to make a computer go to sleep or prevent it from sleeping or hibernating. Using VB Script to Make a Computer Sleep To use the VB Script to make a computer sleep, you can follow these steps: An example of the code is provided by a user on Server Fault: Vb Set sleepSec=3 & set sleepVbs=%temp%\sleep.vbs & echo While True > %sleepVbs% & echo Wend >> %sleepVbs% & cscript %sleepVbs% //B //T:%sleepSec% & del %sleepVbs% In the above code, the sleepSec variable is set to 3, indicating a sleep duration of 3 seconds. The script is then created in the temporary folder (%temp%) with the name sleep.vbs. The script contains a simple infinite loop that continuously checks if the specified sleep duration has been reached. Once the duration is reached, the script is deleted. Using VB Script to Prevent a Computer from Sleeping or Hibernating To prevent a computer from sleeping or hibernating, you can use a VBScript that periodically generates a keypress or keyboard shortcut that does not trigger any actions in the applications or the operating system. For example, CTRL, CapsLock, Numpad5, CTRL+SHIFT+ALT+Tilde, etc. Vb Set WshShell = WScript.CreateObject("WScript.Shell") This code creates a WshShell object using the WScript.CreateObject method, which can be used to simulate keypresses or perform other actions to keep the computer awake. Another example of a VBScript to prevent a computer from sleeping or hibernating is provided by a user on Server Fault: Vb Powercfg -setacvalueindex scheme_current sub_none 7516b95f-f776-4464-8c53-06167f40cc99 This script uses the powercfg command to modify the power settings of the computer, ensuring that it does not enter sleep or hibernation mode. Choosing Between Timeout, Ping, and VB Script While the timeout command is recommended when possible, it is not always an option, especially in non-interactive mode. The ping command is a simple alternative, but it is not ideal as it keeps the CPU busy. The VB Script provides more flexibility and can often do things that batch files cannot, making it a good choice when you need more advanced functionality. You may want to see also
$6.64
$6.99
The Sleep method in VBScript is used to suspend the thread running the script, which releases its CPU utilisation. Execution resumes as soon as the interval expires. This method is useful when running asynchronous operations, multiple processes, or if your script includes code triggered by an event. To use the Sleep method in VBScript, you can use the WScript.Sleep() function. This function takes the number of milliseconds as an argument. For example, to sleep for 1000 milliseconds (1 second), you would use WScript.Sleep(1000). If you are not running your VBScript in the Windows Scripting Host, you may encounter errors when trying to use the WScript object. In this case, you can try calling it with CreateObject, as shown in the following example: Vb Dim shell Set shell = CreateObject("WScript.Shell") Call shell.Run("Sleep -m 1000", 0, True) This code creates a WScript.Shell object and uses it to run the Sleep function with the specified number of milliseconds. Alternatively, you can embed some VB Script within a batch file to achieve the same result. This approach allows you to mix the functionality of batch files with the added capabilities of VBScript. Overall, the Sleep method in VBScript provides a useful way to introduce delays or suspend execution, making it a valuable tool for handling asynchronous operations and multiple processes. You may want to see also You can use the PAUSE command to execute it after some of the other start-ups are finished. You can try using the ping command: ping 127.0.0.1 -n 1 -w 500> nul. Here, 500 is the time in milliseconds. The correct way to sleep in a batch file is to use the timeout command, introduced in Windows 2000. The sleep command is not a standard Windows batch command. To access the sleep command, install the 2003 Windows Resource Kit.Sleep Aids and Cataract Surgery: Safe Combination?
Explore related products

Using the ping command
Marjoram Essential Oil: Your Natural Sleep Aid
Explore related products

Using the Start-Sleep command
Curly Hair Care: Mastering the Sleep Cap
Explore related products

Using the VB Script
Used CPAP Masks: Safe or Not?
Explore related products

Using the Sleep method in VBScript
Magnesium Glycinate: A Natural Sleep Aid
Frequently asked questions














![GenCare Maximum Strength Nighttime Sleep Aid Supplement for Adults Deep Sleep Pills with Diphenhydramine HCl 50mg to Fall Asleep Faster- Strong Non-Habit Forming PM Sleeping [96 Softgels] (Pack of 2)](https://m.media-amazon.com/images/I/81DjMOgUlKL._AC_UY218_.jpg)




















