71

As a power user, I frequently use the Run dialog.

I can understand why the following commands work, as they are in the PATH environment variable.

mspaint
diskmgmt.msc
explorer

These commands also work in CMD.

The commands below work in run, but they are not in the PATH, and they don't work in CMD.

firefox
winword
iexplore

How does Run know where these files are?

89

When you execute a command from Run dialog, the system looks at the App Paths registry key here:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

and

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

EXAMPLE

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\filezilla.exe

(default) value data has the full path to the executable.

If it's not found, it looks at each folder included in the PATH.

Whereas the Command Prompt doesn't reference these registry keys. It only searches the PATH.

  • 5
    Ah, this probably explains why you can't have multiple programs with the same name work as open with options. Poor design. – curiousdannii Aug 6 '16 at 3:43
  • 2
    Yes, almost. But Open with dialog reads from HKCR\Applications and RegisteredApplications – w32sh Aug 6 '16 at 5:39
  • 4
    Microsoft provided a video about this: channel9.msdn.com/Shows/Defrag-Tools/Defrag-Tools-133-App-Paths – magicandre1981 Aug 6 '16 at 6:53
  • 6
    You can of course use the start builtin which does search the app paths. – Neil Aug 6 '16 at 17:09
  • 1
    This is pretty well documented here. I've also explained how cmd does its search here -- it's a bit of a special case distinct from Win32 APIs. – Bob Aug 7 '16 at 5:05
4

w32sh's answer correctly points out that the extra keys searched by the Run dialog are here:

  • HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\
  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\

There is official documentation for these paths.

An important fact about these keys is that the name of the key (e.g. "filezilla.exe") doesn't have to match the full path in any way. Under Windows 7, the value can even be a simple command-line, similar to what can be used as the "target" of a shortcut.

For instance, I used to have this in my registry:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\jedit.exe]
@="\"C:\\WINDOWS\\system32\\javaw.exe\" -Xms24M -Xmx512M -jar \"C:\\Program Files\\jEdit\\jedit.jar\" -reuseview"

I can't seem to make this work in Windows 10, but you can still point at any file, including a batch file, e.g.

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\jedit.exe]
@="C:\\Program Files\\jEdit\\run-jedit.bat"

That allows you to type "jedit" or "jedit C:\foo\bar\something.txt" to run the JVM with appropriate options and launch/reuse jEdit.

As far as I can see, the key name must end in ".exe", so to create an alias of "abc", you create a key "abc.exe", even if it's not pointing to a ".exe" file.

  • It doesn't work here if I use additional switches after the executable file name. – w32sh Aug 8 '16 at 9:14
  • @w32sh Hm, I think it's changed in Win 10 :( – IMSoP Aug 8 '16 at 10:24
-1

There's an environment variable called PATH, or %PATH% in the command line. It contains a series of locations to search through.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.