Batch file opens Default Browser instead of Firefox
I have a login script that runs for every user. The first check sees if the username matches our Test-Taking User (exam). If so, launches Firefox to the exam homepage and stops.
The commands individually work. When I call the .bat
file, it launches Internet Explorer to the website. What am I doing wrong?
@echo off
REM Exam Startup - Username is "exam", then start the Exam website, and exit the script
if %USERNAME% EQU exam (
if exist "%PROGRAMFILES%\Mozilla Firefox\firefox.exe" start "%PROGRAMFILES%\Mozilla Firefox\firefox.exe" "https://www.example.com/"
if exist "%PROGRAMFILES(x86)%\Mozilla Firefox\firefox.exe" start "%PROGRAMFILES(x86)%\Mozilla Firefox\firefox.exe" "https://www.example.com/"
exit
)
...
REM rest of script
Solution 1:
What am I doing wrong?
if exist "%PROGRAMFILES%\Mozilla Firefox\firefox.exe" start "%PROGRAMFILES%\Mozilla Firefox\firefox.exe" "https://www.example.com/"
You have no "title"
in your start
command.
-
If there is no
"title"
thenstart
parses"%PROGRAMFILES%\Mozilla Firefox\firefox.exe"
as a title (because it starts with a"
) and"https://www.example.com/"
as the command to execute. -
Executing the command
"https://www.example.com/"
causes the default browser to open that URL.
Try adding ""
after start
:
if exist "%PROGRAMFILES%\Mozilla Firefox\firefox.exe" start "" "%PROGRAMFILES%\Mozilla Firefox\firefox.exe" "https://www.example.com/"
Syntax
START "title" [/D path] [options] "command" [parameters] Key:
title
Text for the CMD window title bar (required.)path
Starting directory.command
The command, batch file or executable program to run.parameters
The parameters passed to the command.
...
Always include a
title
this can be a simple string like"My Script"
or just a pair of empty quotes""
According to the Microsoft documentation, the title is optional, but depending on the other options chosen you can have problems if it is omitted.
Source start
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- start - Start a program, command or batch script (opens in a new window).