Create and Run a Batch File on Windows 11/10 [Complete Guide]
Have you ever wanted to open multiple programs, run several commands, or automate repetitive tasks on your Windows computer without doing everything manually? That’s where a batch file comes in handy.
A batch file lets you save multiple Command Prompt commands in a single file and execute them together. Instead of typing the same commands every time, you can double-click the file and let Windows run the instructions for you.
For example, you can create a batch file to open Notepad and Calculator, display a custom message, create folders, or perform routine file management tasks. You don’t need to be a programmer to get started. A basic understanding of Windows and a simple text editor are enough.
In this guide, you’ll learn how to create and run a batch file on Windows 11 and Windows 10.
Create and Run a Batch File on Windows

A batch file is a plain-text file containing one or more Windows commands. It typically uses the .bat or .cmd file extension. When you run the file, Windows processes its commands in sequence using the Windows command interpreter.
You can create a batch file using Notepad, save it with the .bat extension, and run it by double-clicking it in File Explorer. You can also execute it through Command Prompt or run it with administrator privileges when the commands require elevated permissions.
Let’s walk through the process step by step.
Step 1: Open Notepad on Your Windows PC
The easiest way to create a batch file is to use Notepad, a simple text editor available on Windows.
First, click the Start button on your taskbar or press the Windows key on your keyboard. Type Notepad in the search box and select the Notepad app from the results.
A blank Notepad window will open. This is where you’ll write the commands you want Windows to execute.
You don’t need to install additional software or download a special batch-file editor. Notepad is enough for creating a basic batch file.
For this guide, we’ll create a simple example that displays a message and opens Notepad. Once you understand the process, you can replace these commands with other tasks you want to automate.
Step 2: Write Commands in Notepad
Now it’s time to add commands to your batch file.
Enter the following example into the blank Notepad window:
@echo off
echo Hello! Your batch file is working.
start notepad.exe
pause
Let’s understand what each line does.
The @echo off command prevents Windows from displaying most commands as they execute, keeping the Command Prompt window cleaner.
The echo command displays the message “Hello! Your batch file is working.” on the screen.
The start notepad.exe command launches Notepad. If Notepad is already open, Windows may open another window or use an existing application process, depending on the circumstances.
Finally, pause keeps the Command Prompt window open and displays a message asking you to press a key to continue. Without it, the command window might close as soon as the batch file finishes.
You can use this example to test your first batch file. Make sure every command is on a separate line. Don’t paste the commands into Command Prompt yet because we’re creating a file that will store them for future use.
Step 3: Save the File With the .BAT Extension
This is one of the most important steps. If you save the file with a .txt extension, Windows will treat it as a regular text document instead of a batch file.
In Notepad, click File > Save As. Choose a location where you can easily find the file, such as your Desktop.
In the File name field, enter:
MyFirstBatch.bat
Next, find the Save as type drop-down menu and select All files (.).
Leave the encoding at its default setting unless your script requires a different encoding. Then click Save.
Your batch file should now appear on the Desktop with the name MyFirstBatch.bat.
If you see a file named MyFirstBatch.bat.txt, Windows may have saved it as a text document. To correct this, repeat the Save As process and make sure you select All files (.) before saving.
You can also display file extensions in File Explorer to make this easier. In Windows 11, open File Explorer, select View > Show > File name extensions. In Windows 10, open the View tab and check File name extensions.
Now you can see whether your file really ends in .bat.
Step 4: Run the Batch File by Double-Clicking It
Once you’ve saved the file correctly, running it is straightforward.
Open your Desktop or the folder where you saved MyFirstBatch.bat. Find the file and double-click it.
A Command Prompt window should appear and display the message you added to the script. Notepad should also launch automatically.
The Command Prompt window will remain open because the script contains the pause command. When you see the message asking you to press a key, press any key on your keyboard to finish the script.
If everything works as expected, congratulations! You’ve successfully created and run your first Windows batch file.
Keep in mind that batch files can execute commands that change files, modify settings, or launch other programs. Only run batch files you created yourself or obtained from a source you trust.
Step 5: Run a Batch File Through Command Prompt
Double-clicking is convenient, but sometimes you may want to run a batch file directly from Command Prompt. This approach is useful when you’re troubleshooting a script or checking its output.
Press Windows + R, type cmd, and press Enter. A Command Prompt window will open.
If your file is saved on the Desktop, enter the following command:
cd /d “%USERPROFILE%\Desktop”
Press Enter. This changes the current directory to your Desktop, including when it is on a different drive.
Next, type the following command:
MyFirstBatch.bat
Press Enter to execute the script.
You should see the same message and application launch as before. If the batch file is saved in another folder, change to that folder first or enter the full path to the file.
For example, you can run a batch file from another location by entering its full path in Command Prompt, using quotation marks if the path contains spaces.
This method also makes it easier to see error messages when a script doesn’t work as expected.
Step 6: Create a Batch File to Open Multiple Programs
Now that you’ve learned the basics, let’s try a more practical example. You can use a batch file to launch multiple applications with one double-click.
Open Notepad and enter the following commands:
@echo off
start “” notepad.exe
start “” calc.exe
start “” mspaint.exe
exit
Save the file as OpenPrograms.bat. Remember to select All files (.) in the Save As window.
Double-click the saved file. Windows should launch Notepad, Calculator, and Microsoft Paint.
The start “” syntax uses an empty window title before the program name. This helps Windows correctly interpret the command, particularly when you later use paths that contain spaces.
The exit command closes the batch file’s Command Prompt session after the commands have been processed. The applications launched by the script can remain open.
If a program doesn’t launch, it may not be installed, or Windows may not be able to locate its executable by name. In that case, you can use the full path to the program’s executable file.
Step 7: Run a Batch File as an Administrator
Some batch files need elevated permissions to change protected system settings, manage certain services, or perform administrative tasks.
To try running a batch file with administrator privileges, locate it in File Explorer, right-click it, and select Run as administrator, if that option is available. Approve the User Account Control prompt if Windows displays one.
However, running a batch file as an administrator does not automatically make every command work. The commands must still be valid, and the account must have the required permissions.
Only grant administrator privileges to scripts you understand and trust. A batch file running with elevated permissions can make significant changes to Windows, including changes that may affect other users or system functionality.
If your script only opens applications or displays messages, administrator privileges generally aren’t necessary.
Edit or Troubleshoot Your Batch File
You can change a batch file whenever you need to update its commands.
Right-click the .bat file and select Edit. Depending on your Windows version and file associations, you may need to select Show more options in Windows 11 before choosing the editing option.
The file should open in Notepad. Make your changes, click File > Save, and close the editor.
Run the file again to test the updated commands.
If the batch file opens in Notepad instead of executing, verify that the filename ends in .bat, not .bat.txt. If nothing happens, open it through Command Prompt to check for error messages.
If a command fails, check the spelling, file path, and command syntax. Some commands also require additional permissions or software that may not be available on your computer.
For troubleshooting, you can temporarily remove @echo off from the first line to make the command execution easier to inspect. Keep pause at the end if you want the window to stay open long enough to read the output.
FAQs
1. Can I create a batch file without installing any software?
Yes. You can create a batch file using Notepad, which is available on Windows 10 and Windows 11. Save the file with a .bat or .cmd extension to make it executable as a command script.
2. What is the difference between .BAT and .CMD files?
Both extensions are used for Windows command scripts. They work similarly for most everyday tasks. Some advanced error-handling behavior can differ between batch files and command scripts, but beginners can generally use either extension for simple automation.
3. Can I run a batch file automatically when Windows starts?
Yes. You can place a batch file in your Windows Startup folder to run it when you sign in. Press Windows + R, enter shell:startup, and press Enter. Place a shortcut to your batch file in the folder. Be careful when automating scripts that make system changes.
4. Why does my batch file open as a text document?
This usually happens because the file was saved with a .txt extension or Windows is hiding known file extensions. Save it again using Save as type: All files (.) and ensure the filename ends in .bat.
5. Are batch files safe to run?
Batch files are not inherently dangerous, but their commands can delete files, change system settings, or run other programs. Review the commands before running a script, and avoid executing unknown batch files or granting them administrator privileges without understanding what they do.
Summary
Creating and running a batch file on Windows is a simple way to automate repetitive tasks. You can use Notepad to write commands, save the file with the .bat extension, and execute it by double-clicking it or running it through Command Prompt.
Start with simple commands, such as displaying a message or opening an application. Once you’re comfortable with the basics, you can create more useful scripts for everyday Windows tasks.
Remember to save the file with the correct extension, test your commands carefully, and run scripts with administrator privileges only when necessary.
With a little practice, batch files can save time and make routine computer tasks much easier.
