29

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.

3
  • This doesn't really have anything to do with Windows 8 in particular, does it?
    – Joey
    Oct 28, 2012 at 17:37
  • I guess it does. In windows 7, only the path would have worked. But in windows 8, the path of the program must be in between quotation marks (what I've found out), or it shows error that it could not locate the program (if the path isn't registered in PATH environment variable or in App registry). Oct 29, 2012 at 11:08
  • 2
    @AhmadulHoq Windows 7 does behave in exactly the same way, as far as I know. You probably had the file in one of those places.
    – Bob
    Oct 31, 2012 at 3:33

7 Answers 7

31

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) or ipconfig (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 command

    When 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 the ShellExecuteEx 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.
5
  • 3
    For completeness, it should be noted that running a program at the command prompt directly as any_program.exe does not search the App Paths key, while running it as start any_program.exe does e.g. on a default Win7 install, entering wordpad at the prompt gives a not recognized error, while start wordpad successfully launches wordpad (based on its App Paths key). Technical reason is that the linked page refers to ShellExecuteEx (which start uses) while CreateProcess (which direct execution uses) specifically mentions that App Paths is not searched.
    – dxiv
    Nov 30, 2015 at 4:08
  • @dxiv Thanks. Turns out direct invocation via cmd only searches the cwd and PATH-listed directories. I'll amend shortly.
    – Bob
    Nov 30, 2015 at 4:13
  • 1
    Thanks, that was quick for a 3-years late comment ;-) The relevant docs-link is msdn.microsoft.com/en-us/library/windows/desktop/ms682425.aspx but I didn't have room to include it in the previous comment. The search logic is listed in #1-6 under lpCommandLine.
    – dxiv
    Nov 30, 2015 at 4:17
  • 1
    @dxiv Thanks for the link. I've also edited that in, though it doesn't seem to match my observed behaviour... (try: set path= followed by cmd can't find it, but start cmd works as it still searches paths outside the env var).
    – Bob
    Nov 30, 2015 at 4:31
  • 1
    Thanks for doublechecking. It is indeed the case that cmd direct execution doesn't search the windows/system directories by default, and I was wrong to point to the CreateProcess docs. Seems that cmd has its own logic, per the "Command Search Sequence" section under technet.microsoft.com/en-us/library/… dating back to at least NT times, and most likely forever before.
    – dxiv
    Nov 30, 2015 at 7:37
11
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.

2
  • What does the empty "" mean?
    – zwcloud
    Nov 18, 2020 at 8:53
  • Run start /? to learn about arguments if you need the details
    – Maximus
    Nov 18, 2020 at 12:35
6

You have two options:

  1. Add the program to your %PATH% variable
  2. Use quotes in your shortcut

Detail:

Adding any_program.exe to path:

  1. Go to "Control Panel" ->"Advanced System Settings"
    Advanced System Settings

  2. Go to the Advanced tab
    System Settings

  3. 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 ;
    path variable

  4. 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.

2
2
  1. Open Command Prompt
  2. Type the name of the program you want to run. If its on the PATH System variable it will be executed. If not, you'll have to type the full path to the program. For example, to run D:\Any_Folder\any_program.exe type D:\Any_Folder\any_program.exe on the Command prompt and press Enter
0
1

I am using a yet simple method . . .
Copy the shortcut of the file to C:\users\name and then type the shortcut's name in run dialog box. . . . .

1

Use CMD to do this instead of GUI.

  1. Making Executable File Location Available In CMD i.e Creating a PATH Variable:

    For Example:

    • Scenario : You Want To Open Acrobat From CMD
    • SET PATH : In CMD Type

      SET ACROBAT="C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat"
      
  2. Executing the file From CMD:

    In CMD Type :

    START ACROBAT
    

That's It !!!
I Hope This Was Helpful.

0

I guess you have to add the path to the PATH variable in system variables

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .