Running a batch file from Command Prompt is straightforward: type the filename with its path, then press Enter

A batch file is a text file containing a list of commands that Command Prompt runs one after another. Batch files end in .bat or .cmd. To run one, open Command Prompt, navigate to the folder where the file lives, type the filename, and press Enter. That's the basic method — but the details matter depending on where your file is, whether it needs administrator access, and what you want to do with the output.

The most common way to run a batch file is to type its name directly if you are already in the same folder, or to type the full path to the file if it is somewhere else. You can also run batch files with special flags that change how Command Prompt behaves after the file finishes.

Key Takeaways

  • Type the batch filename at the Command Prompt and press Enter if the file is in your current folder; otherwise, type the full path to the file.
  • Use cd to change to the folder containing your batch file before running it, or type the complete path without changing folders.
  • Right-click the Command Prompt window title bar and select "Run as administrator" if your batch file needs elevated permissions to work.
  • Add pause as the last line in your batch file to keep the window open after the commands finish, so you can see the results.
  • Use @echo off at the start of a batch file to hide the commands themselves and show only the output.

The simplest method: running a batch file in your current folder

If your batch file is in the folder Command Prompt is already showing, type the filename and press Enter. For example, if your file is called backup.bat, type:

backup.bat

Command Prompt will run every command inside the file in order. The window stays open while the commands run, then closes when they finish — unless the batch file itself contains a pause command at the end.

To check what folder you are currently in, type cd and press Enter. Command Prompt will show your current location. If your batch file is not in that folder, you need either to change folders or type the full path to the file. You can also type dir to list all files in the current folder and confirm your batch file is there.

Running a batch file from a different folder

If your batch file is in a different folder, you have two options: change to that folder first, or type the full path to the file.

Option 1: Change folders, then run the file. Use the cd command to move to the folder containing your batch file. For example, if your file is in C:\Users\YourName\Documents\Scripts, type:

cd C:\Users\YourName\Documents\Scripts

Press Enter. Command Prompt will now show that folder as your current location. Then type the batch filename and press Enter:

backup.bat

Option 2: Type the full path without changing folders. Type the complete path to the batch file in quotes if the path contains spaces. For example:

"C:\Users\YourName\Documents\Scripts\backup.bat"

This method is faster if you only need to run the file once and do not want to navigate folders. The quotes protect the path if any folder name has a space in it.

Running a batch file with administrator permissions

Some batch files need elevated permissions to work — for example, files that modify system settings, install software, or access protected folders. If you try to run such a file and it fails silently or shows a "permission denied" error, you need to run Command Prompt as administrator.

Right-click the Command Prompt window's title bar (the blue bar at the top) and select "Run as administrator" from the menu. Windows will ask for permission; click "Yes". The title bar will now say "Administrator: Command Prompt" instead of just "Command Prompt".

Once you are in the administrator Command Prompt window, navigate to your batch file and run it using either method above. The file will now have permission to execute commands that require elevated access. If you are unsure whether your batch file needs administrator access, try running it normally first — if it fails, then try the administrator version.

Keeping the Command Prompt window open to see results

By default, Command Prompt closes when ready after a batch file finishes running. If the commands run too fast to read, you will miss the output. To keep the window open, add the word pause as the last line in your batch file.

Open your batch file in Notepad (right-click it and select "Edit"), go to the very end, and add a new line with the word pause. Save the file. Now when you run the batch file, it will display "Press any key to continue..." at the end, giving you time to read the output before the window closes.

Alternatively, if you do not want to edit the batch file, you can type this at Command Prompt instead:

cmd /k backup.bat

The /k flag tells Command Prompt to stay open after the batch file finishes. You can then type exit to close it when you are ready. This method is useful if you want to run the batch file once without permanently changing it.

Hiding commands and showing only output

By default, Command Prompt displays each command as it runs, then shows the result. This can make the output hard to read if there are many commands. To hide the commands and show only the results, add @echo off as the first line of your batch file.

Open your batch file in Notepad, go to the very beginning, and add a new line with @echo off. Save the file. Now when you run the batch file, Command Prompt will not display the commands themselves — only their output.

If you want to see the commands again later, straightforward delete or comment out that line by typing rem before it. You can also add @echo on partway through a batch file to start showing commands again from that point forward. This is helpful when you are testing a batch file and need to see what is happening at each step.

Troubleshooting common problems

If Command Prompt says "is not recognized as an internal or external command", the file is not in the current folder and you did not type the full path correctly. Check the spelling of the filename and the path. Use dir to list the files in your current folder and confirm the batch file is there, or use cd to navigate to the correct folder.

If the batch file runs but nothing happens, the commands inside may be failing silently. Add pause to the end of the batch file so you can see any error messages. You can also add echo commands throughout the file to print messages at each step, which helps you see where the file stops working. For example, add echo Starting backup process at the beginning to confirm the file is running at all.

If you get a "permission denied" error, the file needs administrator access. Close Command Prompt, right-click it in the Start menu, select "Run as administrator", and try again. Some batch files that modify Windows settings or access system folders will not work without elevated permissions.

Frequently Asked Questions

Can I run a batch file by double-clicking it instead of using Command Prompt?

Yes. Double-clicking a .bat or .cmd file will run it directly. However, the Command Prompt window closes when ready when the file finishes, so you cannot see the output. Using Command Prompt gives you more control and lets you see what happened.

What is the difference between .bat and .cmd files?

.bat files are older and work on all Windows versions. .cmd files are newer and have slightly more features, but both work the same way in Command Prompt. You run them identically.

How do I run a batch file every time I start my computer?

You can add a shortcut to your batch file in the Windows Startup folder, or use Task Scheduler to run it at a specific time. Both methods are more advanced than running it manually from Command Prompt, but they automate the process.

Can I run multiple batch files one after another?

Yes. Create a new batch file that calls the other batch files using their full paths. For example, a file called run_all.bat could contain two lines: C:\path\to\first.bat and C:\path\to\second.bat. When you run run_all.bat, it will run both files in order.

What does the /k flag do when I type cmd /k?

The /k flag tells Command Prompt to run the command that follows it, then stay open instead of closing. This is useful for running a batch file and then having the window remain so you can type more commands or see the output.