2

I was looking for a way to add only one specific executable file from a certain directory to the PATH environmental variable. Instead of adding the whole directory C:\Program Files\Firefox Beta I would like to add only one file C:\Program Files\Firefox Beta\firefox.exe, but I doesn't work that easily.

I found a hint to register the application in the registry under Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths as explained here: https://docs.microsoft.com/en-us/windows/win32/shell/app-registration#registering-verbs-and-other-file-association-information, but it doesn't seem to work.

I have added the key Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe and set the (Default) entry to C:\Program Files\Firefox Beta\firefox.exe. Also I have added a Path entry and set it to C:\Program Files\Firefox Beta. The result looks like this, but as you can see in the CMD window, it doesn't work.

Screenshot

Is it possible to achieve what I'm looking for? What's the correct way to do it?

2
  • Did you open a new command window? Have you tried rebooting?
    – DavidPostill
    Mar 31, 2021 at 18:19
  • Yes, this is after I restarted the computer. Mar 31, 2021 at 18:54

3 Answers 3

1

What you have added to the registry is a verb to a file-type. This method is used for example to specify the viewer program for .pdf files, or the printer program for such files. This doesn't do what you want.

In addition, it's not possible to add files to the PATH, only folders can be added. Adding a file to PATH has no effect, as you have already found out.

I can only see one option here, which is to add the entire folder C:\Program Files\Firefox Beta to the PATH.

If you wish to avoid that, as a workaround you may create a folder that will contain a .bat file named firefox.bat that will execute firefox.exe. Include that folder in the PATH, to be able to use firefox as a command. You will avoid this way adding the whole folder C:\Program Files\Firefox Beta to the PATH.

3
  • That's unfortunate, I don't want to bloat the PATH variable with all the other executable in the same folder. I was wondering if maybe there is another way without using the PATH variable that makes it possible to run firefox.exe from the command line? Mar 31, 2021 at 20:23
  • You may create a folder that will contain a .bat file named firefox.bat that will cd to that folder and execute firefox.exe. Include that folder in the PATH, to be able to use firefox as a command. You will avoid this way adding the whole C:\Program Files\Firefox Beta to the PATH.
    – harrymc
    Mar 31, 2021 at 20:30
  • I have created a one-liner @"C:\Program Files\Firefox Beta\firefox.exe" %*, saved it as C:\Program Files\Firefox Beta\bin\firefox.bat and added the directory to the PATH variable. It actually seems to work until now. Just wondering if there are any hidden drawbacks? Mar 31, 2021 at 21:32
0

The reason it doesn't work is that Cmd.exe doesn't use that feature. It a graphical thing for typing in places like Start - Run dialog.

You can force Cmd.exe to use graphical features by using the start command.

So start firefox.

Better would be

 doskey firefox="C:\Program Files\Firefox Beta\firefox.exe" $*

You can add this to

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor
Autorun=doskey firefox="C:\Program Files\Firefox Beta\firefox.exe" $*

So it is set each time command prompt is started.

See doskey /? and start /? for options.

-1

Rightclick This PC -> Properties -> Advanced System Settings -> Environment Variables

1
  • 1
    This only allows folders, which is specifically not what OP wants. Mar 31, 2021 at 21:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .