57

Possible Duplicate:
Why am I able to execute a program that is not in my PATH environment variable?

I was teaching a coworker about %PATH% and found that if I run "Firefox", it works, but was surprised to see that it was not in my path.

What am I missing?

Mathew
  • 592
  • 5
  • 9
  • 2
    It depends on the context. If you're entering "firefox" from a command line, then firefox.exe must either be in the path or in the Windows or Windows\System32 folders. If you're entering "Firefox" in the Run dialog, the App Paths registry is used, so firefox.exe is registered there. – boot13 Jul 25 '12 at 13:20
  • Thanks boot13, I was not aware of the App Paths registry keys. – Mathew Jul 25 '12 at 13:30

1 Answers1

100

If you're trying to run an executable by only specifying its name, Windows looks for the file in the following locations:

  1. The current working directory.
  2. The Windows directory only (no subdirectories are searched).
  3. The Windows\System32 directory.
  4. Directories listed in the PATH environment variable.
  5. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths (also HKEY_CURRENT_USER since Windows 7)

Microsoft actually recommends "registering" applications in the App Paths subkey to avoid the need for applications to modify the system PATH environment variable. The application's installer will register the executable.

Jan Fabry
  • 157
  • 2
  • 10
JC2k8
  • 2,949
  • 1
  • 23
  • 23
  • 3
    One of the best answers to a question I've ever seen. +1 – Everett Jul 25 '12 at 13:19
  • That was it, thank you sir. Learn something new everyday. – Mathew Jul 25 '12 at 13:28
  • 8
    @Mathew You're welcome. Keep in mind that the "App Paths" subkey also exists in the HKCU hive for applications that were installed for **one user** only. – JC2k8 Jul 25 '12 at 13:36
  • 1
    So that's why I never really had to muck around with the PATH until I went from .NET development to Java development. I never really considered why everything in .NET development "just works"! – Stephen Swensen Jul 25 '12 at 18:59
  • I'd assume the reason things like Java, etc. don't utilize the App Paths subkey is because the .NET Framework is much more closely associated with the Windows API, so it's a lot easier to take advantage of the registry; meanwhile, on the Java/etc. side, not using App Paths requires less changes to standard libraries in order to enable portability (as *nix systems usually also have (some equivalent to) the PATH environment variable). A holdover from simpler days, I suppose? – JAB Jul 25 '12 at 19:04
  • *nix computers allways uses the environment variable PATH. Some shells, like csh, do have a mapping between the shells variable path and the environment variable PATH. But execvp(2) uses PATH variable. If the command isn't there, it will not find it. It doesn't look in any other place, unless there are no PATH variable, then it looks in /bin:/usr/bin:. – Anders Jul 25 '12 at 22:33
  • .net apps, which are still .exe files, are still subject to the same .exe search order, app paths etc. – David Heffernan Jul 26 '12 at 07:42
  • 2
    This is only true for the Windows Run dialog, in cmd.exe and powershell only 1. through 4. are used, see also boot13's comment. – Alexander Jul 26 '12 at 12:21