Suppose I have a program named any_program.exe and my operating system drive is C:. The location of the program is D:\Any_Folder\any_program.exe
How do I start/execute that program via command prompt in Windows 8?
I have tried the command line START any_program.exe, but it shows me an error that
Windows cannot find 'any_program.exe'. Make sure you typed the name correctly, and then try again.
By the way, it worked perfectly in Windows 7. And, if I type START notepad.exe or START firefox.exe (Firefox is not installed in C: drive), it works in Windows 8.
Answer
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:
echocalls 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
startcommandWhen you try to execute a file through the
startcommand, Command Prompt does not perform any searching. Instead, it passes the file name (and arguments) over to Windows itself (via theShellExecuteExAPI 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.
No comments:
Post a Comment