How do I open a program via the command prompt in Windows 8?
There are three basic ways to run a 'command' in the Command Prompt.
builtins ("internal commands")
These are commands built into cmd itself, and do not require an external program invocation. They also do not perform any searching, and will always be executed with the highest priority if matched. You can bypass builtins by wrapping the executable name in quotes:
echo
calls the builtin, but"echo"
would search following cmd rules.Direct invocation
This is when you directly specify a program name (without a path). For example, if you run
cmd
(cmd.exe
) oripconfig
(ipconfig.exe
) at the prompt, you are directly calling the external command. This performs limited searching implemented entirely within the Command Prompt, in this order:- The current directory.
- The directories that are listed in the PATH environment variable.
(thanks to dxiv for the comments)
Through the
start
commandWhen you try to execute a file through the
start
command, Command Prompt does not perform any searching. Instead, it passes the file name (and arguments) over to Windows itself (via theShellExecuteEx
API call), which must then search for the file's location. There are several places it searches in the following order:- Current working directory
- Windows directory
- Windows\System32 directory
- Directories listed in PATH environment variable
- Registry defined App Paths
Note that the Run dialog also uses this search method.
Normally, you can either navigate to the location of the file with cd /d D:\Any_Folder
(/d
means change drive) and just run any_program.exe
. Alternatively, you can specify the full path D:\Any_Folder\any_program.exe
.
If you want to start it with start any_program.exe
, you have a couple of options:
- You can put it in the Windows or System32 directories, or any directory in the PATH environment variable.
- You can add the directory it is located in (
D:\Any_Folder
) to the PATH environment variable, see this question for details. - You can add it to the App Paths registry key, as Notepad and Firefox does. App Paths links a file keyword (such as
firefox.exe
) with the full path to the file, unlike the other options that deal with directories. See here for more information.
start D:\Any_Folder\any_program.exe
or, when path or file contains spaces
start "" "D:\Any_Folder\any_program.exe"
start any_program.exe
works only for those programs, who are located in %PATH%
environment variable, or registered in registry in the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
or its HKEY_CURRENT_USER
analogue.
You have two options:
- Add the program to your
%PATH%
variable - Use quotes in your shortcut
Detail:
Adding any_program.exe
to path:
Go to "Control Panel" ->"Advanced System Settings"
Go to the Advanced tab
Click on "Environment Variables" Add the folder in which any_program.exe resides. Edit the PATH Variable and add the folder in the end, separated by a
;
You can now use any_program.exe in the run dialog box (Try logging out and back to make sure your path variable changes are used.)
Using complete path
Instead of using any_program.exe
in the Run dialog, you need to use the complete PATH. So type D:\Stuff\App\any_program.exe
in the run dialog instead.