devcrea

How to Run an EXE File from CMD: Arguments, Admin Rights & Errors

Learn how to execute EXE files using Command Prompt. Covers passing arguments, handling spaces in paths, running as Administrator, and keeping the window open.

// The short answer

Run an executable from Command Prompt with its full path, quoting paths that contain spaces, for example "C:\Program Files\App\tool.exe" --help. Dragging the file into the CMD window inserts the path safely, while running from an elevated prompt is only necessary when the program needs administrator rights or protected resources.

Full walkthrough, edge cases and why it works
In this guide · 5 sections
  1. 01The Drag & Drop Method (Easiest Way)
  2. 02The Professional Method: Using cd Command
  3. 03How to Run EXE with Administrator Privileges
  4. 04Advanced: Passing Arguments & Logging Output
  5. 05Troubleshooting: Why Does My Program Close Instantly?

Double-clicking an icon is easy, but it leaves you in the dark when things go wrong. If you are trying to debug a crashing program, pass specific startup arguments, or just want to feel like a power user, the Command Prompt (CMD) is your best friend. Running an executable from the command line gives you full control over the process, allowing you to catch error messages that usually disappear in a fraction of a second.

Whether you are a developer testing a build or a gamer trying to launch a server with custom flags, mastering these commands is essential.

The Drag & Drop Method (Easiest Way)

If you are not comfortable typing long file paths or worried about making a typo, this trick is a lifesaver. You don't need to memorize the exact location of your file.

  1. Open Command Prompt (Press Win + R, type cmd, and hit Enter).

  2. Type the name of the program you want to run (if it's in the system path) or just leave the cursor blinking.

  3. Open the folder containing your .exe file in File Explorer.

  4. Drag the file and drop it directly into the black CMD window.

Windows will automatically paste the full path for you, complete with quotation marks if there are spaces in the folder names. Press Enter, and you are good to go.

The Professional Method: Using cd Command

While drag-and-drop is great for one-off tasks, you will often need to work within a specific directory, especially if your program relies on other files (like .dll or config files) in the same folder. This is where the cd (Change Directory) command comes in.

To switch to the folder where your application lives, use the cd command followed by the path.

dos1 line
cd C:\Users\YourName\Downloads

Once you are in the correct directory, you can simply type the name of the file (e.g., program.exe) to run it. If you are looking to manage system behaviors or restart services after this, knowing how to reboot windows cmd can also be very useful for your workflow.

Handling Spaces in Paths

This is the most common error beginners face. If your folder name has a space, like Program Files, CMD might misinterpret it as two separate commands. To fix this, always wrap your path in double quotes.

dos1 line
cd "C:\Program Files\My Application"

Switching Drives (The /d Trick)

By default, the cd command acts within the current drive (usually C:). If your game or program is installed on a secondary drive like D: or E:, typing cd D:\Games won't work on its own. You need to add the /d switch.

dos1 line
cd /d D:\Games\MyGame

How to Run EXE with Administrator Privileges

Some programs require elevated permissions to modify system files or write to protected folders. If you try to run them from a standard CMD window, you might get an "Access Denied" error.

To solve this, you don't need a special code inside the terminal. Instead, you must launch the terminal itself with high privileges:

  1. Press the Windows key and type cmd.

  2. Right-click on Command Prompt.

  3. Select Run as administrator.

Now, any .exe you launch from this window will inherit those admin rights. This is often necessary when setting up system-level tools or modifying environment variables for your development setup.

Advanced: Passing Arguments & Logging Output

Command-line tools often accept "arguments" (or flags) that change their behavior. These are specific instructions written after the file name.

For example, to run a program in "silent" mode or force a specific resolution, you might type:

dos1 line
setup.exe /silent /norestart

Saving the Output (Logging)

If a program runs too fast and you can't read the text it spits out, you can redirect that output to a text file using the > symbol. This is incredibly useful for troubleshooting.

dos1 line
diagnose.exe > log.txt

After running this, nothing will appear on the screen, but a file named log.txt will be created in that folder containing all the output.

Troubleshooting: Why Does My Program Close Instantly?

You double-click an EXE, a black window pops up, and then it vanishes instantly. This happens because the program finishes its task (or crashes) and Windows closes the session immediately.

To see what happened, do not double-click. Instead:

  1. Open CMD first.

  2. Navigate to the folder using the cd command.

  3. Run the executable by typing its name.

By doing this, the CMD window stays open even after the program terminates, allowing you to read any error messages or exit codes. If you are moving towards more complex scripting, you might also want to explore PowerShell scripts as a more modern alternative to batch files and CMD commands.

Quick answers

Frequently asked questions

How do I run an EXE file located on a different drive, like D or E?

Standard navigation commands often fail when switching drives because you need to explicitly tell the system to change the drive letter. You should use the command cd /d followed by the full path, such as cd /d D:\Games, to switch both the drive and the directory simultaneously. Alternatively, you can simply type the drive letter followed by a colon (e.g., D:) and press Enter to switch drives before navigating to your specific folder.

Why does the Command Prompt window close immediately after running my program?

This usually occurs because the application finishes its task or encounters an error and terminates instantly, causing Windows to close the session before you can read the output. To solve this, do not double-click the file; instead, open a Command Prompt window first, navigate to the folder using the cd command, and type the file name manually to keep the window open after execution.

What should I do if my file path contains spaces, like "Program Files"?

Command Prompt treats spaces as separators between commands or arguments, which often leads to "path not found" errors when navigating to folders with multi-word names. To fix this, you must always wrap the entire path in double quotation marks, for example, cd "C:\Program Files\My App", ensuring the system reads it as a single valid location.

How can I run an EXE file with Administrator privileges from CMD?

You cannot elevate a program's permissions from inside a standard Command Prompt window using a simple command like sudo in Linux. You must start the terminal itself with high privileges by searching for "cmd" in the Start menu, right-clicking the icon, and selecting Run as administrator before launching your executable.

Something wrong or out of date?

Tools change fast. Tell the editor what no longer works.