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
  • 24
  • 120
  • 163
  • You can also create shortcuts of your own, besides the built-in Windows ones. Create a directory and put the path in your system PATH statement, then create shortcuts to any folder, program, or file you want, give them any name you want, and place them in this directory. Opening RUN and typing the name you gave the shortcut will take you to the folder, or open the file or program that shortcut points to. – music2myear Oct 31 '14 at 15:40

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
  • 455,459
  • 31
  • 526
  • 924
  • It's not entirely correct to state regarding feature #2 that *The first word typed into the box is taken as a command, while the following ones are taken to be parameters.* For example in my `%userprofile%` folder I have a folder named `My Folder` (note the space). If in the Run box I type `my folder` it opens the correct folder. I think your second statement prevails: *If the entered command-name matches a folder name, that folder will be opened in Explorer **even if the folder name contains spaces.*** – I say Reinstate Monica Oct 23 '14 at 23:08
  • @Twisty: You are right - I corrected my answer. – harrymc Oct 24 '14 at 05:49
2

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
  • 12,837
  • 5
  • 37
  • 69
  • The Shell.ShellExecute method you quote has nothing to do with C programs, which the Run box is most probably written in. Perhaps you meant the [ShellExecute function](http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx), which unfortunately only looks in the PATH. The %USERPROFILE% variable is only consulted by the Run box program itself, not by the core API of Windows. This answer doesn't really make any sense. – harrymc Oct 25 '14 at 07:45
  • 1
    @Harrymc maybe the answer doesn't really make any sense for you, but Windows (or Windows Explorer, or the core API, or any other Windows part) **behaves** this way! Sorry I don't have so deep look into Windows; I don't need it in this case... However, I _know_ it has nothing to do with the `ShellExecute function` – JosefZ Oct 25 '14 at 09:50
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

  • The behavior of the *Run* box is not a direct replacement of the `START` command. For example, you cannot type from a Command Prompt `start my subfolder` and have it open a folder named *My Subfolder*. You would instead type `start "" "my subfolder"` (the first set of double quotes are required.) – I say Reinstate Monica Oct 23 '14 at 23:14
  • the quotes are required only if **subfolder**'s name contains whitespace (`ascii 32`); the initial `""` here is for defining console window title, as `start` interprets it's first quoted argument as the string to define the title –  Oct 24 '14 at 08:57
  • you're correct the first set of quotes are only required if the subfolder's name includes spaces. My point is that in such a case the first set of quotes are indeed *required*, making the syntax of the command quite different when using `START` vs. the *Run* dialog box. Thus the *Run* box is *not* just a GUI version of the START command. – I say Reinstate Monica Oct 28 '14 at 18:36