I want to add time delay in my batch file. The batch file will be running silently at backgorund. Please help me.
This question is related to
batch-file
wait
sleep
You want to use timeout. timeout 10 will sleep 10 seconds
ping localhost -n (your time) >nul
example
@echo off
title Test
echo hi
ping localhost -n 3 >nul && :: will wait 3 seconds before going next command (it will not display)
echo bye! && :: still wont be any spaces (just below the hi command)
ping localhost -n 2 >nul && :: will wait 2 seconds before going to next command (it will not display)
@exit
timeout 5
to delay
timeout 5 >nul
to delay without asking you to press any key to cancel
Ok, yup you use the timeout
command to sleep. But to do the whole process silently, it's not possible with cmd/batch. One of the ways is to create a VBScript that will run the Batch File without opening/showing any window.
And here is the script:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "PATH OF BATCH FILE WITH QUOTATION MARKS" & Chr(34), 0
Set WshShell = Nothing
Copy and paste the above code on notepad and save it as Anyname.**vbs ** An example of the *"PATH OF BATCH FILE WITH QUOTATION MARKS" * might be: "C:\ExampleFolder\MyBatchFile.bat"
Source: Stackoverflow.com