2/21/2023 0 Comments Windows batch file time delaySo if I slept for 30 seconds the actual wait time would be 31 seconds (roughly 3% off). A slower system would likely take longer. I got about an average 950ms (about 1 sec) inaccuracy on each call, because that was the time it took to load PowerShell.exe. It’s not recommended you use this as a command in any repetitive way, especially if you’re relying on any amount of accuracy when doing the sleep operation. Powershell.exe takes a significant amount of time to load.Support milliseconds (albeit inaccurately due to con #1).Powershell.exe -command "Start-Sleep -Milliseconds 5000" Please note that you must specify 6 pings in order for it to wait 5 seconds, since it’s the actual time between pings that causes the delay. The one thing better is ping.exe has been around longer than timeout.exe, so it should support more older Windows OS’s (timeout.exe was introduced with Vista). This method is similar to timeout.exe in the sense that it is limited to whole seconds. This can be used to (somewhat) reliably make your bat file sleep. You could setup your own dummy IP that will cause a timeout to occur, but that’s a lot of work for something like this.īetween each packet, ping.exe will wait 1 second. This script relies on a valid IP that doesn’t respond and causes the timeout to elapse. 1.1.1.1 is a valid IP address and if the IP owner decides to make it start responding to pings one day, you’re screwed.It would always result in about 1/2 second accuracy, but even that didn’t seem to be correct in most cases. Although it takes a millisecond value, the precision seems to be very bad from my testing.Works on older OS’s: ping.exe has been with Windows since at least Windows 2000 (likely even NT4).If %endTime% LSS %startTime% set set /A duration=%startTime%-%endTime% :: For some stupid reason if the hour < 10, it uses a blank space instead of a leading zero If !timeRemaining! GTR 1200 ( timeout /nobreak /t 1 >nul 2>&1 ) Set /A timeRemaining=!sleepFor!-!timeDiffMs! If !timeDiffMs! GTR !sleepFor! ( goto :return ) :: Note, dont use a for loop, the cmd prompt would try to expand each iteration, and that is a big problemĬall :getTimeDiff result !startTime! !curTime! If the duration is more than 1second away, it will call timeout.exe to wait (can easily be modified to use ping.exe for better compatibility with older Windows). The function is quite simple, it starts a loop and checks if the duration has expired. This method requires the use of a custom bat file function. Likewise, if it actually takes 130 its difference is +30 – or if it’s 80, then its difference is -20.īelow are additional details on each method and my final conclusion (tl dr read conclusion). If a command is expected to wait for 100ms, and it actually waits 100ms, the difference is 0. Red or yellow colors are bad, and closer to 0 is good. Here is a breakdown of the commands to illustrate which has the highest difference between the expected time and the actual time it waits. * only applies if method supports partial seconds Type the following command and press Enter: powercfg.Command: echo WScript.Sleep^(WScript.Arguments^(0^)^) >"%temp%sleep.vbs" & cscript "%temp%sleep.vbs" 5000 >nulĮach method was executed multiple times with the durations:.Type the following command and press Enter: powercfg.exe /SETDCVALUEINDEX SCHEME_CURRENT SUB_VIDEO VIDEOCONLOCK 600 Important: You must change “600” in the command-line with the timeout time you want to use, in seconds.To change the Lock screen timeout using Command Prompt, do the following: Type the following command and press Enter: powercfg.exe /SETACTIVE SCHEME_CURRENTĬhanging the Lock Screen Timeout when running on Battery.Type the following command and press Enter: powercfg.exe /SETACVALUEINDEX SCHEME_CURRENT SUB_VIDEO VIDEOCONLOCK 600 Important: You must change “600” in the command-line with the timeout time you want to use, in seconds.Right click on command and choose to run as an Administrator.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |