Batch file to run multiple programs with delays [closed]

Posted on

QUESTION :

Well i am new to Batch things, so need some help.
I understand the lowest level, but with more complicated things have problems.
Thing that i need now is File that launches other files, but with period of 30 secs or so.

Like:
Open Calculator
after 30 secs
Open Skype
after 30 secs
Open Notepad

How can i make this in a batch file? Preferably it should not show the CMD window.

Also if you can explain How the time things work it would be really nice.

ANSWER :

Without any additional software installed, use a normal Ping command to add delays

ping -n <delay_in_seconds> localhost 
start calc
ping -n <delay_in_seconds> localhost
start notepad
  • The parameter -n XX stands for how many pings should be executed, not for how long should be waited until next command. The delay between two pings is normally 1 second. In your example, you want to add 30 x 1s delays with ping -n 30 localhost

  • With localhost as ping destination you ping your own machine since we do not really want to send and receive a ping package

  • Suppress the CMD output with @echo off or localhost > nul


Without any additional software installed, you can utilize VBscripts Run method to run and hide batch files while executing. If you set “intWindowStyle” to 0, the Window is hidden.

object.Run(strCommand, [intWindowStyle], [bWaitOnReturn]) 

Create a new text file at the same folder as your batch file and save it as HiddenStart.vbs.
Paste the following two lines and replace <batch_file> with your actual batch file name. Prepend a path if the batch file isn’t at the same folder.

Set wShell = CreateObject ("Wscript.Shell") 
wShell.Run "cmd /c <batch_file>", 0

Beside 0 as second parameter you can also use one of the following Window states

0   Hides the window and activates another window.
1   Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. 
2   Activates the window and displays it as a minimized window. 
3   Activates the window and displays it as a maximized window. 
4   Displays a window in its most recent size and position. The active window remains active.
5   Activates the window and displays it in its current size and position.
6   Minimizes the specified window and activates the next top-level window in the Z order.
7   Displays the window as a minimized window. The active window remains active.
8   Displays the window in its current state. The active window remains active.
9   Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. 
10  Sets the show-state based on the state of the program that started the application.

In the end you will have two files: A VBS file to start a hidden CMD and the CMD itself which starts your programs with custom delays.

enter image description here

hidecon.exe

start calc.exe
sleep 30

start "" "C:Program FilesSkypeskype.exe"
sleep 30

start notepad.exe

Leave a Reply

Your email address will not be published.