6

After reading an answer I learned that certain folders have a special feature

USERPROFILE AKA C:\Users\Steven
SystemRoot  AKA C:\Windows

From the Run box, you can access any subfolders of these. For example entering Documents will bring up C:\Users\Steven\Documents. Do any other folders have this feature, or can this feature be added to a folder?

Zombo
  • 1

3 Answers3

3

As Arakel has said, there are here two unrelated features:

  1. Environment variables that are used as %variable%, for example %USERPROFILE%
  2. Commands that one enters without %...%, for example documents.

Actually, the first ones are just macros that have values. The syntax %...% just converts the variable-name to text, and this text is then executed as if it was typed into the Run box.

The entered text is first searched in the folders specified by the PATH environmental variable and in %USERPROFILE%. In this case the entire entered text must equal the folder name. Examples here are "documents" for C:\Users\<user>\Documents or "videos" for C:\Users\<user>\Videos.

If a folder by that name was not found, the first word typed into the box is taken as a command, while the following ones are taken to be parameters. Words containing separators such as blanks need to be quoted.

If the entered command-name does not match a folder name, Windows will try to find an executable in the PATH that has that exact name. If the command does not have a suffix, Windows will try all executable suffixes such as .exe or .bat (and some more). There are virtually hundreds of command-names that can be entered this way.

For example, typing calc will start the Windows calculator, which is the executable file C:\Windows\System32\calc.exe, because C:\Windows\System32 is in the PATH.


One can create one's own Run commands, in this way :

  1. Win+R to open the Run dialog
  2. Enter %windir% to open the Windows directory
  3. Alt+F W S to open the File menu, choose the New menu item, then the Shortcut menu item
  4. Go through the wizard to create a shortcut to the desired program or folder
  5. The name you give to the shortcut is what you will type in the Run box to start the program.

Another method is done via the registry (not recommended). Microsoft calls it Application Registration.

  1. Run Regedit and navigate to following key:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
    
  2. Right-click on the App Paths key and select the New / Key command.

  3. Give the new key a name of 2-8 characters name followed by .exe
  4. Change the value if the (Default) item to the full path to the program.

For example, this sample registry file lets one type ie in the Run box to open Internet Explorer:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ie.exe]
@="C:\\Program Files\\Internet Explorer\\iexplore.exe"
harrymc
  • 498,455
3

Windows Run box attempts to invoke Shell.ShellExecute method (default operation of registered file type) for file specified by text in the input field, namely in the current directory, which is %USERPROFILE%!

Suppose we write MyLoc Sets here and hit Enter.

At first, the word MyLoc supposed to be a command. The shell searches for an executable variant, e.g. MyLoc.com, MyLoc.exe, MyLoc.bat, MyLoc.cmd, ... in the current directory, then in directories specified by the %PATH% environmental variable, then for \SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Myloc.exe registry key under HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE hives. As a last resort, the shell searches for MyLoc Sets folder in the same locations (except of the registry). File not found error...

And now, try Local Settings: found no executable named Local, but found a folder of this name under %USERPROFILE%! Thus, as a folder is registered file type, and the default operation for a folder used to be "Explore", then it can be performed by the ShellExecute method...

JosefZ
  • 13,855
0

it seems the run box is just a gui version of start command with the default /d %userprofile% switch value which sets the path for starting directory

as every other command it reacts to %path%, %pathext% etc special environment variables

moreover it understands the pattern to directly open web pages, eg ctrl+r (or start) www.superuser.com opens the website with the default web browser application, as it knows that the argument is url this time

the interesting part on these environment variables is the order of items in the list they contain, as it matters for setting search priority, and is important when looking for homonymous files or directories