How does the Run dialog know where applications are?

71

18

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?

mt025

Posted 2016-08-05T16:48:19.583

Reputation: 2 392

Answers

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.

w32sh

Posted 2016-08-05T16:48:19.583

Reputation: 8 611

5Ah, this probably explains why you can't have multiple programs with the same name work as open with options. Poor design. – curiousdannii – 2016-08-06T03:43:23.190

2Yes, almost. But Open with dialog reads from HKCR\Applications and RegisteredApplications – w32sh – 2016-08-06T05:39:01.983

4

Microsoft provided a video about this: https://channel9.msdn.com/Shows/Defrag-Tools/Defrag-Tools-133-App-Paths

– magicandre1981 – 2016-08-06T06:53:03.957

6You can of course use the start builtin which does search the app paths. – Neil – 2016-08-06T17:09:46.050

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 – 2016-08-07T05:05:56.963

@curiousdannii can you elaborate? We can have multiple processes with the same name running in Windows – phuclv – 2016-08-08T04:26:45.170

@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 – 2016-08-08T04:29:32.327

@curiousdannii: Not possible using UI but you can do so by editing the registry. – w32sh – 2016-08-08T04:48:16.117

@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 – 2016-08-08T04:53:13.430

Correct. But you can do so using regedit.exe. If you have a specific requirement, pls post a new question. – w32sh – 2016-08-08T04:58:36.107

@curiousdannii why not? For example MS Word is associated with .doc, .docx, .docm, .dot, .dotx, .dotm... – phuclv – 2016-08-08T05:32:05.283

@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 – 2016-08-08T05:37:24.360

@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 – 2016-08-08T05:40:15.203

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

Posted 2016-08-05T16:48:19.583

Reputation: 638

It doesn't work here if I use additional switches after the executable file name. – w32sh – 2016-08-08T09:14:41.023

@w32sh Hm, I think it's changed in Win 10 :( – IMSoP – 2016-08-08T10:24:46.300

-1

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

Garhoogin

Posted 2016-08-05T16:48:19.583

Reputation: 111