Batch file to run multiple programs with delays

3

1

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.

Eka

Posted 2013-08-31T20:38:19.180

Reputation: 69

Question was closed 2013-09-01T18:01:19.487

2

Use the resources available on http://ss64.com/nt/ and try to learn form them.

– Doktoro Reichard – 2013-08-31T20:40:29.387

Virtually any vintage DOS book cover batch command and batch files extensively. I suggest getting one of them and start reading. – user539484 – 2013-08-31T20:52:59.147

1If you can't understand the sleep command then obviously you do not 'understand the lowest level'. This truly is the simplest batch file you could ever make and all you need to make it is knowing what commands are available. Doktoro has been kind enough to give you the command list, I've been kind enough to tell you the specific command. All that is left is for you to find out how to execute a programme without waiting for it to exit. You have everything you need, try to use that knowledge first then come back if you have problems. – Mokubai – 2013-08-31T20:58:37.447

Show your work so far, we are here to help not do the work. Also, batch is nearing dead. I would invest in PowerShell if you do not have a specific reason to learn batch. – Austin T French – 2013-08-31T20:59:19.670

Answers

4

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

nixda

Posted 2013-08-31T20:38:19.180

Reputation: 23 233

Does not hide console window. – Vlastimil Ovčáčík – 2013-09-01T09:34:17.210

@VlastimilOvčáčík Now it does – nixda – 2013-09-01T09:37:47.860

3

hidecon.exe

start calc.exe
sleep 30

start "" "C:\Program Files\Skype\skype.exe"
sleep 30

start notepad.exe

Vlastimil Ovčáčík

Posted 2013-08-31T20:38:19.180

Reputation: 1 835

It will wait until Calculator is closed, then wait 30 seconds. – gronostaj – 2013-08-31T21:02:40.613

@gronostaj: of course it does, thanks for pointing out the trivial mistake. – Vlastimil Ovčáčík – 2013-08-31T21:18:22.723