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 (The Lazy Shortcut)
  2. 02The Proper Way: Navigating with the cd Command
  3. 03Running as an Administrator
  4. 04Getting Fancy: Startup Flags & Saving Logs
  5. 05That Annoying Window That Closes Instantly

Double-clicking an icon is second nature for most of us, but the moment an app crashes without warning, you’re left staring at your desktop with zero clues. If you need to figure out why software keeps failing, feed it custom startup parameters, or simply want to understand what Windows is doing under the hood, the Command Prompt is your best bet. Running an executable directly from the terminal puts you in the driver’s seat, making it easy to catch those split-second error codes that normally vanish before you can read them.

Whether you're compiling your own code, testing an experimental build, or trying to spin up a dedicated game server with custom launch flags, getting comfortable with these basic terminal habits will save you endless headaches.

The Drag & Drop Method (The Lazy Shortcut)

If you dread typing out mile-long folder paths and don’t want to deal with frustrating typos, this little trick will quickly become your favorite shortcut. You don’t need to remember where a deeply nested file lives or manually piece together its location.

  1. Fire up Command Prompt (just tap Win + R, type cmd, and press Enter).
  2. If your program happens to sit in a registered system path, type its name; otherwise, just leave your prompt sitting there.
  3. Open up File Explorer and track down the folder holding your .exe.
  4. Click and drag the executable file straight into the Command Prompt window.

Windows handles the tedious part by typing out the entire path for you, complete with quotation marks around any spaces. Hit Enter, and the program spins up immediately.

The Proper Way: Navigating with the cd Command

While dragging and dropping works wonders for a quick one-off run, you’ll usually want to actually park yourself inside the right folder. Many programs depend on sibling files - like companion .dll libraries or local configuration files - that won't load properly unless the terminal is already working inside that directory. That’s where the classic cd (Change Directory) command comes into play.

Getting Into the Right Folder

To jump into whichever folder holds your application, type cd followed by the directory path.

DOS

code1 line
cd C:\Users\YourName\Downloads

Once the prompt reflects that you're in the right spot, simply type the executable's name (like program.exe) and hit Enter to launch it. If you happen to be tweaking system services or updating background tools along the way, knowing how to reboot windows cmd is another handy command to keep in your back pocket.

Dealing with Spaces in File Names

This one trips up almost everyone when they're first starting out. If a folder contains spaces - such as the standard Program Files directory - the Command Prompt will get confused and treat the space as a command separator. To dodge that syntax error, simply wrap the entire folder path inside quotation marks.

DOS

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

Jumping Across Different Drives (The /d Switch)

Here’s an odd quirk: by default, cd only moves around inside whichever drive letter is already active (usually your C: drive). If you keep your games or workspace on a secondary drive like D: or E:, typing cd D:\Games by itself won't actually move you there. You have to include the /d flag so Windows knows to swap drives, too.

DOS

code1 line
cd /d D:\Games\MyGame

Running as an Administrator

Plenty of utilities need elevated privileges to do their job, especially if they touch Windows system files, modify registry entries, or write to protected system directories. Try running one of these from a regular terminal window, and Windows will promptly throw an "Access Denied" error in your face.

The trick here isn't typing a fancy internal command. Instead, you just have to give the terminal window itself admin privileges right from the start:

  1. Tap the Windows key and type cmd.
  2. Right-click on Command Prompt in the search results.
  3. Click Run as administrator.

Once that elevated terminal opens up, any .exe you trigger from inside it automatically inherits full administrator permissions. This is practically a requirement when you're setting up low-level developer tools or tweaking system environment variables.

Getting Fancy: Startup Flags & Saving Logs

A lot of command-line tools can take extra parameters (often called flags or arguments) that adjust how they behave. You just write these flags immediately following the program's file name before pressing Enter.

For instance, if you want an installer to run quietly in the background without prompting you or forcing an automatic reboot, you might type:

DOS

code1 line
setup.exe /silent /norestart

Capturing What the Program Says (Logging)

When a program fires off diagnostic details and closes too fast to read, you can pipe all of that terminal output straight into a plain text file using the > symbol. It makes debugging issues significantly easier.

DOS

code1 line
diagnose.exe > log.txt

When you hit Enter, you won't see anything print onto the terminal screen. Instead, CMD silently dumps every line of text into a freshly created file called log.txt right inside that folder.

That Annoying Window That Closes Instantly

We’ve all had this happen: you double-click an executable, a black window blinks onto the screen for a millisecond, and then it vanishes without a trace. That happens because console utilities are designed to quit the moment they finish their job (or crash), and Windows automatically closes the window as soon as the process ends.

If you actually want to see what went wrong, skip the double-click:

  1. Open your Command Prompt window first.
  2. Navigate straight to the application's folder using cd.
  3. Launch the file manually by typing its name.

Because you launched the program from an already active terminal, the window stays wide open after the program exits, leaving any output codes or crash reports right there for you to inspect. If you find yourself wanting more automation and modern features down the road, taking a look at PowerShell scripts is a natural next step beyond standard batch files.

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.