How do I open a program via the command prompt in Windows 8?

17

8

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.

Ahmadul Hoq

Posted 2012-10-28T09:14:52.280

Reputation: 275

This doesn't really have anything to do with Windows 8 in particular, does it? – Joey – 2012-10-28T17:37:04.783

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). – Ahmadul Hoq – 2012-10-29T11:08:15.627

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 – 2012-10-31T03:33:40.050

Answers

24

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.

Bob

Posted 2012-10-28T09:14:52.280

Reputation: 51 526

3For 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 – 2015-11-30T04:08:18.447

@dxiv Thanks. Turns out direct invocation via cmd only searches the cwd and PATH-listed directories. I'll amend shortly. – Bob – 2015-11-30T04:13:06.583

1

Thanks, that was quick for a 3-years late comment ;-) The relevant docs-link is https://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 – 2015-11-30T04:17:45.613

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 – 2015-11-30T04:31:34.767

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 https://technet.microsoft.com/en-us/library/cc723564.aspx#XSLTsection127121120120 dating back to at least NT times, and most likely forever before.

– dxiv – 2015-11-30T07:37:44.163

7

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.

Maximus

Posted 2012-10-28T09:14:52.280

Reputation: 19 395

5

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.

Nemo

Posted 2012-10-28T09:14:52.280

Reputation: 1 126

those screenshots are WAAAY to large. Mind having them at a reasonable size? – Journeyman Geek – 2012-10-28T09:30:15.617

Working on it... – Nemo – 2012-10-28T09:34:13.110

Path directories on Windows are delimited by semicolons (;), not colons (:)... – Bob – 2012-10-28T09:39:48.547

I had that in my mind, but still mis-typed it. – Nemo – 2012-10-28T09:42:39.993

Screenshots taken from http://www.c-sharpcorner.com/UploadFile/6cde20/use-of-environment-variable-in-windows-8/ apparently . The screenshots there are terrible

– Journeyman Geek – 2012-10-28T09:52:24.467

Will change to something better in a while. I'm working on Ubuntu right now. – Nemo – 2012-10-28T10:00:59.190

1

  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

Rakib Ansary

Posted 2012-10-28T09:14:52.280

Reputation: 2 168

Haha nice trick! – Ahmadul Hoq – 2013-05-01T07:41:20.257

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

prad_

Posted 2012-10-28T09:14:52.280

Reputation: 11

0

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.

DnyanDeep Taur

Posted 2012-10-28T09:14:52.280

Reputation: 9

0

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

pratnala

Posted 2012-10-28T09:14:52.280

Reputation: 1 866