How is a program that's not in my path being run?

57

18

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

Posted 2012-07-25T13:04:19.063

Reputation: 592

Question was closed 2012-07-26T19:36:33.773

2It 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 – 2012-07-25T13:20:51.353

Thanks boot13, I was not aware of the App Paths registry keys. – Mathew – 2012-07-25T13:30:00.793

Answers

101

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.

JC2k8

Posted 2012-07-25T13:04:19.063

Reputation: 2 813

3One of the best answers to a question I've ever seen. +1 – Everett – 2012-07-25T13:19:07.580

That was it, thank you sir. Learn something new everyday. – Mathew – 2012-07-25T13:28:48.563

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 – 2012-07-25T13:36:45.623

1So 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 – 2012-07-25T18:59:21.617

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 – 2012-07-25T19:04:07.363

*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 – 2012-07-25T22:33:29.967

.net apps, which are still .exe files, are still subject to the same .exe search order, app paths etc. – David Heffernan – 2012-07-26T07:42:07.360

2This 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 – 2012-07-26T12:21:49.673