# open multiple programs Batch file



## becarta (Dec 1, 2008)

Hello all. I made this code for opening programs easy
But it needs some improvement.

Now i can choose 1 number and it opens that number. 
What i want is choose al the numbers you want separately by a , and that he opens al the programs
How can i do that ?

```
@echo off
cls

TITLE Programma's

echo 1)  Firefox
echo 2)  Msn    
echo 3)  Word
echo 4)  Cod 4 Rcon
echo 5)  Teamspeak
echo 6)  Xfire
echo 7)  Utorrent
echo 8)  Photoshop
echo 9)  Donut
echo 10) Teamviewer 3
echo 11) Windows Mobile Apperaten
echo x) Afsluiten
:a
set /p ans=Choose Your Program:

if '%ans%'== '1' GOTO Firefox
if '%ans%'== '2' GOTO Msn
if '%ans%'== '3' GOTO Word
if '%ans%'== '4' GOTO Cod 4 Rcon
if '%ans%'== '5' GOTO Teamspeak
if '%ans%'== '6' GOTO Xfire
if '%ans%'== '7' GOTO Utorrent
if '%ans%'== '8' GOTO Photoshop
if '%ans%'== '9' GOTO Donut
if '%ans%'== '10' GOTO Teamviewer
if '%ans%'== '11' GOTO WMApp
if '%ans%'== 'x' GOTO Afsluiten

GOTO a

:Firefox
cd "C:\Program Files\Mozilla Firefox\"
start firefox.exe
GOTO a

:Msn
cd "C:\Program Files\Windows Live\Messenger\"
start msnmsgr.exe

GOTO a

:Word
cd "C:\Program Files\Microsoft Office\Office12\"
start WINWORD.EXE

GOTO a

:Cod 4 Rcon
cd "C:\Program Files\ModernRcon\"
start ModernRcon_v0.8.exe

GOTO a

:Teamspeak
cd "C:\Program Files\Teamspeak2_RC2\"
start TeamSpeak.exe

GOTO a

:xfire
cd "C:\Program Files\Xfire\"
start xfire.exe

GOTO a

:Utorrent
cd "C:\Program Files\uTorrent\"
start uTorrent.exe

GOTO a

:Photoshop
cd "C:\Program Files\Adobe\Adobe Photoshop CS2"
start Photoshop.exe

GOTO a

:Donut
cd "C:\Users\Richard\Desktop\Progamma's"
start U.exe

GOTO a

:Teamviewer
cd "C:\Program Files\TeamViewer3\"
start TeamViewer.exe

GOTO a

:WMApp
cd "C:\Program Files\TeamViewer3\"
start TeamViewer.exe

GOTO a

:Aflsuiten
exit
```


----------



## -Fabez- (Jul 28, 2008)

The command prompt will wait for the first program to finish before it starts another one so it would be easier to use a higher level language such as Python in order to achieve this.


----------



## becarta (Dec 1, 2008)

I would like to make this in c++ but i dont have the knowledge for that. I will try python thats new for me. 

thx for the response


----------



## -Fabez- (Jul 28, 2008)

Python is a brilliant high level language and I will be happy to help if you encounter any problems


----------



## TheOutcaste (Aug 8, 2007)

-Fabez- said:


> The command prompt will wait for the first program to finish before it starts another one


That's true if you call the program directly, but he's using *Start*. Using *Start*, it will only wait if you use the */wait* switch.


becarta said:


> ```
> :Teamviewer
> cd "C:\Program Files\TeamViewer3\"
> start TeamViewer.exe
> ...


You are starting the same program for #10 and #11. I'm assuming a typo, so that will need to be corrected.

This will allow you to enter multiple program numbers at one time separated by commas. You can enter the *x* to exit at any point in the string, it will start all programs before exiting. Program numbers can be entered in any order, and will be started in the order entered.

This uses the trick that passing a variable containing a comma to another file or a subroutine _without_ using quotes replaces the comma with a space.


```
@Echo off
cls

TITLE Programma's

Echo 1)  Firefox
Echo 2)  Msn    
Echo 3)  Word
Echo 4)  Cod 4 Rcon
Echo 5)  Teamspeak
Echo 6)  Xfire
Echo 7)  Utorrent
Echo 8)  Photoshop
Echo 9)  Donut
Echo 10) Teamviewer 3
Echo 11) Windows Mobile Apperaten
Echo x) Afsluiten
:a
Set /p ans=Choose Your Program:
Set eflag=0
Set ans=%ans: =%
Echo %ans% |Find /I ",">Nul
If %Errorlevel%==1 (Call :single %ans%) Else (call :multiple %ans%)
If %eflag%==1 Exit
Goto a
:single
If [%1]==[1] Start "C:\Program Files\Mozilla Firefox\firefox.exe"
If [%1]==[2] Start "C:\Program Files\Windows Live\Messenger\msnmsgr.exe"
If [%1]==[3] Start "C:\Program Files\Microsoft Office\Office12\WINWORD.EXE"
If [%1]==[4] Start "C:\Program Files\ModernRcon\ModernRcon_v0.8.exe"
If [%1]==[5] Start "C:\Program Files\Teamspeak2_RC2\TeamSpeak.exe"
If [%1]==[6] Start "C:\Program Files\Xfire\xfire.exe"
If [%1]==[7] Start "C:\Program Files\uTorrent\uTorrent.exe"
If [%1]==[8] Start "C:\Program Files\Adobe\Adobe Photoshop CS2\Photoshop.exe"
If [%1]==[9] Start "C:\Users\Richard\Desktop\Progamma's\U.exe"
[COLOR=Red]If [%1]==[10] Start "C:\Program Files\TeamViewer3\TeamViewer.exe"
If [%1]==[11] Start "C:\Program Files\TeamViewer3\TeamViewer.exe"[/COLOR]
If /I [%1]==[x] Set eflag=1
Goto :EOF
:multiple
If [%1]==[] Goto :EOF
Call :single %1
Shift
Goto :Multiple
```
HTH

Jerry


----------



## becarta (Dec 1, 2008)

Hello TheOutcaste

I tryed your code but i have a question.
When i open a program whit my code it opens the program. you can see at this screen http://img20.imageshack.us/img20/4718/mineqm2.jpg

When i use you code it das this.
http://img392.imageshack.us/img392/3711/yourmw3.jpg

I tryed some things to make it work but no succes.
Mabye you know it

Edit :
I tryed in cmd to use Start "C:\Program Files\Xfire\xfire.exe" that is also not working.
But when i do this.
cd\Program Files\Xfire\ and then start xfire.exe it will start xfire. 
So i think that 2 steps are needed.


----------



## becarta (Dec 1, 2008)

Found the solution


```
@Echo off
cls 

TITLE Your Program

Echo 1)  Firefox
Echo 2)  Msn    
Echo 3)  Word
Echo 4)  Cod 4 Rcon
Echo 5)  Teamspeak
Echo 6)  Xfire
Echo 7)  Utorrent
Echo 8)  Photoshop
Echo 9)  Donut
Echo 10) Teamviewer 3
Echo 11) Windows Mobile Apperaten
Echo x) Afsluiten
:a
Set /p ans=Choose Your Program:
Set eflag=0
Set ans=%ans: =%
Echo %ans% |Find /I ",">Nul
If %Errorlevel%==1 (Call :single %ans%) Else (call :multiple %ans%)
If %eflag%==1 Exit
Goto a
:single
If [%1]==[1] cd\Program Files\Mozilla Firefox\
If [%1]==[1] start firefox.exe
If [%1]==[2] cd\Program Files\Windows Live\Messenger\
If [%1]==[2] start msnmsgr.exe
If [%1]==[3] cd\Program Files\Microsoft Office\Office12
If [%1]==[3] Start WINWORD.EXE
If [%1]==[4] cd\Program Files\ModernRcon\
If [%1]==[4] Start ModernRcon_v0.8.exe
If [%1]==[5] cd\Program Files\Teamspeak
If [%1]==[5] start TeamSpeak.exe
If [%1]==[6] cd\Program Files\Xfire\
If [%1]==[6] start xfire.exe
If [%1]==[7] cd\Program Files\uTorrent\
If [%1]==[7] start uTorrent.exe
If [%1]==[8] cd\Program Files\Adobe\Adobe Photoshop CS2\
If [%1]==[8] start Photoshop.exe
If [%1]==[9] cd\Users\Richard\Desktop\Progamma's\
If [%1]==[9] start U.exe
If [%1]==[10] cd\Program Files\TeamViewer3\
If [%1]==[10] start TeamViewer.exe
If [%1]==[11] cd\Windows\WindowsMobile\
If [%1]==[11] start wmdc.exe /show
If /I [%1]==[x] Set eflag=1
Goto :EOF
:multiple
If [%1]==[] Goto :EOF
Call :single %1
Shift
Goto :Multiple
```


----------



## TheOutcaste (Aug 8, 2007)

That's what I get for testing with Notepad.
Didn't have any of the other programs except Firefox on the PC yesterday, and didn't test with it for some reason
The Start command let's you specify the path by using the /D switch, so the following should work, at least it did with Firefox, MSN Messenger, and MS Word on another system.
I also added the /I switch, just in case other batch files are run before this one that may modify the environment.
I also changed it to use the %ProgramFiles% variable instead of hard coding the path, so it won't matter what drive your Program Files folder is actually on. (Unless a previous batch file changes that variable).

```
If [%1]==[1] Start /D /I "%ProgramFiles%\Mozilla Firefox\" firefox.exe
If [%1]==[2] Start /D /I "%ProgramFiles%\Windows Live\Messenger\" msnmsgr.exe
If [%1]==[3] Start /D /I "%ProgramFiles%\Microsoft Office\Office12\" WINWORD.EXE"
If [%1]==[4] Start /D /I "%ProgramFiles%\ModernRcon\" ModernRcon_v0.8.exe
If [%1]==[5] Start /D /I "%ProgramFiles%\Teamspeak2_RC2\" TeamSpeak.exe
If [%1]==[6] Start /D /I "%ProgramFiles%\Xfire\" xfire.exe
If [%1]==[7] Start /D /I "%ProgramFiles%\uTorrent\" uTorrent.exe
If [%1]==[8] Start /D /I "%ProgramFiles%\Adobe\Adobe Photoshop CS2\" Photoshop.exe
If [%1]==[9] Start /D /I "C:\Users\Richard\Desktop\Progamma's\" U.exe
If [%1]==[10] Start /D /I "%ProgramFiles%\TeamViewer3\" TeamViewer.exe
If [%1]==[11] Start /D /I "%windir%\WindowsMobile\" wmdc.exe /show
```
You can also combine the cd and start commands on the same line like this:


```
If [%1]==[1] cd /D C:\Program Files\Mozilla Firefox\ & start firefox.exe
```
The /D switch and drive letter would only be needed for the CD command if the batch file is run from another drive.

HTH

Jerry


----------



## becarta (Dec 1, 2008)

Some time it wont work.
at this on



> If [%1]==[4] Start /D /I "%ProgramFiles%\ModernRcon\" ModernRcon_v0.8.exe


I get the error he cant find the path.
But what i have works and i want to give it a nice look. so i will give python a try when i know how it works


----------



## TheOutcaste (Aug 8, 2007)

Does it work using this:


```
If [%1]==[4] cd\Program Files\ModernRcon\
If [%1]==[4] Start ModernRcon_v0.8.exe
```
or this:

```
If [%1]==[4] "cd\Program Files\ModernRcon\" & Start ModernRcon_v0.8.exe
```
If so, it may be just that program is setting it's Working directory in a non-standard manner, and you can use one of the above for that program. You may want to make a bug report to the Author as well.

If those also give an error, then you need to double check that the file is actually in c:\Program Files\ModernRcon\

I'll have to download it and see if I get the same error. Might not work as I don't have COD though...

Jerry


----------



## TheOutcaste (Aug 8, 2007)

Remove the /I switch, then it should work. Don't know why, but that fixed it on my XP system.

```
If [%1]==[4] Start /D "%ProgramFiles%\ModernRcon\" ModernRcon_v0.8.exe
```
If there are other programs that fail, try that for them as well.
Jerry


----------

