Batch file to run two or more programs with a delay


If you have a regular need to run two or more programs, but not immediately one after another, wanting a delay in between, you can create a batch file to achieve this. Normally a batch file will execute all programs immediately and there is no command that would produce a pause. However, there is a utility that will help you to achieve this. It is called Sleep. So, let’s see an example.

Suppose you need a way to 1) Close all of your running programs automatically, with just a mouse click or keyboard shortcut, 2) Give some time to your PC to perform a smooth close of these programs, 3) ShutDown your PC completely without you being there to press the Shutdown button.

Here is batch file you could write (paste the text in Notepad, and save it with a *.bat extension – e.g. as “PC-shutdown.bat”:

start "" "C:\any directory\CloseAll.exe"
start /wait "" "c:\any directory\Sleep.exe" 30
start "" "C:\any directory\BrutusShutdown2006.exe"

The batch file above uses 3 utilities to perform an unattended ShutDown of your PC. (Please note that this particular example won’t work, since “CloseAll” closes the window of the batch file too, not giving it time to ‘sleep’ and open Brutus. The only solution I can think of right now, would be to have two shortcuts, one to run close all, and another one for Brutus. This, of course, means 2 mouse clicks, instead of just one.)

1) CloseAll will close all running applications – normally, as if you were there to give them a Close/Exit command.
2) Sleep (if CloseAll gave it the time) would make your batch file wait for 30 seconds (you can increase or decrease this), in order to give to your programs some time to perform ending tasks. For example, Emule, if it has a long list of downloads, may need 30 or more seconds before it closes.
3) Brutus Shutdown would finally make sure your PC closes completely, even by terminating hung applications that did not obey to the initial simple “Close” command given to them by CloseAll.

You can modify the batch file above to meet your needs by replacing the programs of the example with whatever you need to run automatically and after various delay times. You can create a shortcut to your batch file and place it to the Taskbar or Start Menu. You can even assign a keyboard shortcut – or, if you use a keyboard the lets you customize some keys, assign it to a keyboard key – and perform a complex task, with just a mouse click or with just pressing a keyboard key or shortcut.