This article was co-authored by wikiHow staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions.
This article has been fact-checked, ensuring the accuracy of any cited facts and confirming the authority of its sources.
This article has been viewed 562,221 times.
Learn more...
If you need to run a batch file at the Windows Command Prompt, you'll just need to know the location of the batch file. To run the file at the command line, simply type the full path to the batch file and press Enter. Or, if you don't want to type the full path to the file, you can use the cd command to enter the folder containing the .BAT file, type the batch file's name, and then press Enter. This wikiHow guide will teach you 2 simple ways to run a batch file from the Command Prompt in Windows, help you fix common errors, and show you a few other cool ways to run batch files on your PC.
Things You Should Know
- Use the "cd" command to enter the folder that contains your batch file.
- To run the batch file, type its name and press "Enter."
- You can also type the full path to the batch file from any folder to run batch files from anywhere.
Steps
Running from the Batch File's Folder
-
Open the Command Prompt. If your batch file performs administrative tasks, open Command Prompt as an administrator. If the batch file only requires access to files in your user account, you don't need to start it as an administrator.
- Press the Windows key on your keyboard.
- Type cmd.
- If your batch file doesn't need administrator rights, click Command Prompt.
- If your batch file does require administrator rights:
- Right-click Command Prompt.
- Select Run as administrator.
- Click Yes.
-
Type cd followed by the full path to your batch file's folder. The cd command stands for "change directories." For example:
- If the file is at D:\Music\MP3s\Unsorted, you'd type cd D:\Music\MP3s\Unsorted.
- If the batch file is on your desktop, you'd type cd \Users\YourLoginName\Desktop.
- If you use OneDrive to automatically back up your personal files, you'd use cd \Users\YourLoginName\OneDrive\Desktop instead.
- If you don’t know your login name, type cd \Users and press Enter. Then, type dir and press Enter to see a list of users.
Advertisement -
Press ↵ Enter. This will move you into the folder containing your batch file.
- Type dir and press Enter to see a list of all files in the current folder. You should see your batch file (ending with .bat) here.
-
Type the name of the batch file and press ↵ Enter. For example, if your batch file is called program.bat, type program.bat and press Enter. This runs the batch file.
Running from Anywhere
-
Get the full path to your batch file. If you want to run a batch file without using cd to enter its folder first, you'll just need to know the full path to the file. For example, C:\Users\wikiHow\Scripts\mybatchfile.bat. Here's an easy way to find the full path to your batch file:
- Navigate to your batch file. If you're not sure where you saved it, you can search for it.
- If you're using Windows 11, right-click the file and select Copy as path (Windows 11).
- On Windows 10 and earlier, right-click the file and select Properties. Highlight the path next to "Location" and press Ctrl + C to copy it to your clipboard.
-
Open the Command Prompt. If your batch file performs administrative tasks, open Command Prompt as an administrator. If it only requires access to files in your user account, you don't need to start it as an administrator.
- Press the Windows key on your keyboard.
- Type cmd.
- If your batch file doesn't need administrator rights, click Command Prompt.
- If your batch file does require administrator rights:
- Right-click Command Prompt.
- Select Run as administrator.
- Click Yes.
-
Type or paste the full path to your batch file. To paste the path you copied earlier, press Ctrl + V.
- Alternatively, you can type the full path to your file manually (e.g., C:\Users\wikiHow\Scripts\mybatchfile.bat).
- Because the .BAT extension is executable, you don't need to type any commands before pasting or entering the path to the file.
-
Press ↵ Enter to run the batch file. The batch file will now run. Any commands in the batch file will execute as specified in the script.
Expert Q&A
-
QuestionAfter I run the batch script, it just opens another line and nothing happens.Nicole Levine, MFANicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions.
wikiHow Technology WriterMany batch scripts won't display any confirmation that the commands have run. If you wrote the batch script yourself, you can switch the value of "echo" to "on" to display the commands at the prompt as they run. You can also add "pause" to the end of the script to make it prompt the user to press a key to continue. But in general, as long as you don't see an error, that means the batch script executed properly. -
QuestionWhat does this error mean? '.' is not recognized as an internal or external command, operable program or batch file.wikiHow Staff EditorThis answer was written by one of our trained team of researchers who validated it for accuracy and comprehensiveness.
Staff AnswerwikiHow Staff EditorStaff AnswerThe batch script is trying to run "." as a command, which is not a recognized command. Look for the extra period somewhere in the script and remove it. -
QuestionHow do I get out after I run my batch file ?wikiHow Staff EditorThis answer was written by one of our trained team of researchers who validated it for accuracy and comprehensiveness.
Staff AnswerwikiHow Staff EditorStaff AnswerJust click the '''X''' at the top corner of the command prompt window to close it. Or, if the batch script is hung on a process and not letting you go to the next line, you can press Ctrl + C to stop the batch file from running.
Video
Tips
Warnings
- Never run a .BAT file as an administrator unless you know exactly what the file does. If the batch file is malicious, running it as an administrator could steal your data, install malware and viruses, and other dirty deeds.Thanks
- Be careful when downloading .BAT files from the web or as email attachments. Make sure your PC is always protected by Microsoft Defender (or your preferred antivirus software) before running files from unknown sources.Thanks
References
About This Article
1. Press the Windows + R keys.
2. Click Browse.
3. Select the .bat file.
4. Click Open.
5. Click OK.