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?

Braiam
  • 4,709
  • 3
  • 26
  • 57
mt025
  • 3,280
  • 2
  • 21
  • 39

3 Answers3

88

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.

w32sh
  • 11,524
  • 2
  • 39
  • 44
  • 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 06 '16 at 03:43
  • 2
    Yes, almost. But Open with dialog reads from `HKCR\Applications` and `RegisteredApplications` – w32sh Aug 06 '16 at 05:39
  • 4
    Microsoft provided a video about this: https://channel9.msdn.com/Shows/Defrag-Tools/Defrag-Tools-133-App-Paths – magicandre1981 Aug 06 '16 at 06:53
  • 7
    You can of course use the `start` builtin which does search the app paths. – Neil Aug 06 '16 at 17:09
  • 1
    This is pretty well [documented here](http://msdn.microsoft.com/en-us/library/windows/desktop/ee872121%28v=vs.85%29.aspx). I've also explained how cmd does its search [here](http://superuser.com/a/494548/117590) -- it's a bit of a special case distinct from Win32 APIs. – Bob Aug 07 '16 at 05:05
  • @curiousdannii can you elaborate? We can have multiple processes with the same name running in Windows – phuclv Aug 08 '16 at 04:26
  • @LưuVĩnhPhúc You can't have multiple file associations with the same executable file name. Or at least I haven't figured out how – curiousdannii Aug 08 '16 at 04:29
  • @curiousdannii: Not possible using UI but you can do so by editing the registry. – w32sh Aug 08 '16 at 04:48
  • @w32sh The annoying thing is even if you pick out an app using the file selector the UI gives you, it will use an existing app if it has the same file name. – curiousdannii Aug 08 '16 at 04:53
  • Correct. But you can do so using regedit.exe. If you have a specific requirement, pls post a new question. – w32sh Aug 08 '16 at 04:58
  • @curiousdannii why not? For example MS Word is associated with .doc, .docx, .docm, .dot, .dotx, .dotm... – phuclv Aug 08 '16 at 05:32
  • @LưuVĩnhPhúc I mean that you can't associate .doc with two programs in two different directories if the filename of both is word.exe (without using regedit that is.) – curiousdannii Aug 08 '16 at 05:37
  • @w32sh I wasn't wanting to derail this or get support for my issues - I only originally commented because I thought your post was interesting, and it taught me something new: that Windows likes to operate on path-less filenames sometimes. – curiousdannii Aug 08 '16 at 05:40
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.

IMSoP
  • 1,455
  • 10
  • 12
-1

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

Garhoogin
  • 141
  • 1
  • 1
  • 9