Reputation: 11
@echo off
set /P user= Enter number:
echo You have entered %user%
if %user%
(
start "C:\Program Files\Mozilla Firefox\firefox.exe"
)
else if %user%
(
start "C:\Program Files\google chrome\chrome.exe"
)
else
Pause
Upvotes: 0
Views: 101
Reputation: 55
The correct format of "IF...ELSE..." is :
IF %user% (
start "C:\Program Files\Mozilla Firefox\firefox.exe"
) ELSE (
IF %user% (
start "C:\Program Files\google chrome\chrome.exe"
) ELSE ( sth. )
)
the ELSE must follow the round bracket in the same line.
Upvotes: 0
Reputation: 38642
You can use the choice command too:
@Echo Off
Echo 1. Firefox
Echo 2. Chrome
Echo 3. Internet Explorer
Choice /C 123 /M "Please make your choice"
If ErrorLevel 3 (Set "BEP=Internet Explorer\iexplore.exe"
) Else If ErrorLevel 2 (Set "BEP=Google Chrome\chrome.exe"
) Else Set "BEP=Mozilla Firefox\firefox.exe"
If Exist "%ProgramFiles%\%BEP%" Start "" "%ProgramFiles%\%BEP%"
Upvotes: 0
Reputation: 13
I hope this solves your problem
@echo on
set /P user=Enter number:
echo You have entered %user%
IF /i "%user%" == "1" goto 1
IF /i "%user%" == "2" goto 2
:1
cd "C:\Program Files\Mozilla Firefox"
start firefox.exe
exit
:2
cd "C:\Program Files\google chrome"
start chrome.exe
exit
When the user enters 1 the first program is execute when 2 the second
Upvotes: 0
Reputation: 2862
The code below lets the user to choose whether they want to open chrome or Firefox by choosing y for Firefox and n for chrome you can change the inputs to 1 or 2 or what ever you like.
Check if your paths are correct to the .exes
(Paths are different on my PC)
@echo off
set user=
set /P user=Type input y/n: %=%
pause
if "%user%" == "y" goto mozzila
if "%user%" == "n" goto chrome
:mozzila
cd C:\Program Files\Mozilla Firefox\
firefox.exe
:chrome
cd C:\Program Files\google chrome\
chrome.exe
Pause
Upvotes: 0
Reputation: 18837
You can do like this with a Menu :
@Echo OFF
Mode 60,12 & color 9E
Title Start and open a Program
:MENU
CLS
ECHO.
ECHO =====================================================
ECHO PRESS 1, 2 OR 3 to select your task, or 4 to EXIT.
ECHO =====================================================
ECHO.
ECHO 1 - Open Firefox
ECHO 2 - Open Chrome
ECHO 3 - Open Internet Explorer
ECHO 4 - EXIT
ECHO.
SET /P "user=Type 1, 2, 3, or 4 then press ENTER : "
IF "%user%"=="1" GOTO Firefox
IF "%user%"=="2" GOTO Chrome
IF "%user%"=="3" GOTO Internet Explorer
IF "%user%"=="4" GOTO EOF
GOTO MENU
:Firefox
start "" "Firefox.exe"
GOTO MENU
:Chrome
start "" "chrome.exe
GOTO MENU
:Internet Explorer
Start "" "iexplore.exe"
GOTO MENU
Upvotes: 1