A batch file in Windows is a simple script that lets you run multiple commands automatically without typing each command separately. It can help you open programs, create folders, copy files, clear temporary files, and perform other routine tasks with just a double-click.
Batch files are especially useful if you regularly perform the same actions on your Windows 11 or Windows 10 PC. Instead of repeating those steps every time, you can write the commands once, save them in a file with the .bat extension, and run the file whenever you need it.
In this guide, you’ll learn how to create, save, run, edit, and troubleshoot a batch file, even if you’re trying it for the first time.
Create a Batch File in Windows [Complete Guide]

To create a batch file in Windows, follow these steps:
- Open Notepad from the Windows Start menu.
- Type the commands you want Windows to execute.
- Select File > Save As in Notepad.
- Enter a filename ending in .bat, such as MyScript.bat.
- Change the Save as type option to All files.
- Save the file in a folder you can easily access.
- Double-click the saved batch file to run the commands.
These steps work on most Windows 11 and Windows 10 computers. However, the exact result depends on the commands you include in your script.
Step 1: Open Notepad in Windows
The first step is to open a text editor where you can write your batch commands. Notepad is a good choice because it comes with Windows and saves plain-text files without adding unnecessary formatting.
To open it, select Start > Search > type Notepad > Open. You can also press Windows + R, type notepad, and press Enter.
Once Notepad opens, you’ll see a blank editing area. This is where you’ll enter your commands. You don’t need to install a separate application or change any Windows settings to get started.
For this guide, you’ll create a simple batch file that displays a message in Command Prompt. After that, you can experiment with commands for opening applications or managing files.
Step 2: Write Your First Batch File Command
Now that Notepad is open, enter the following code:
@echo off
echo Hello! Your batch file is working.
pause
Each line has a specific purpose. The @echo off command prevents Windows from displaying each command as it executes. The echo command displays the message you specify, while pause keeps the Command Prompt window open until you press a key.
This is a simple and safe example that lets you check whether your batch file works correctly.
You can replace the message with your own text. For example, change Hello! Your batch file is working. to Welcome to my Windows batch script.
Remember that batch files execute commands in the order you write them. If you place a command at the beginning, Windows generally runs it before moving to the next line.
Step 3: Save the File With the .BAT Extension
After entering the commands, save the file in the correct format. This step matters because Windows may otherwise save your script as an ordinary text document.
In Notepad, select File > Save As. Choose a location, such as your Desktop, so you can find the file easily. In the File name field, type MyFirstBatch.bat.
Next, change Save as type from Text Documents to All files. If you see an encoding option, the default selection is generally fine for a basic script.
Select Save to finish. Your file should now appear with the .bat extension.
The complete process is Notepad > File > Save As > File name > All files > Save.
If you save the script as MyFirstBatch.bat.txt, Windows may treat it as a text document instead of a batch file. Always check the extension before moving on to the next step.
Step 4: Show File Extensions in File Explorer
Sometimes, Windows hides known file extensions, which makes it harder to tell whether your script was saved correctly. If you can’t see .bat at the end of the filename, enable file extensions in File Explorer.
On Windows 11, open File Explorer > View > Show > File name extensions. On Windows 10, open File Explorer, select the View tab, and check File name extensions.
Now, look at the file you created. Its name should appear as MyFirstBatch.bat, not MyFirstBatch.bat.txt.
If you find that the file ends in .txt, rename it and remove the extra extension. Windows may display a warning about changing the file type. Confirm the change only when you’re sure the filename ends with .bat.
This small adjustment can save you time when creating or troubleshooting batch scripts.
Step 5: Run the Batch File
Once you’ve saved the file correctly, you’re ready to test it. Navigate to the folder where you saved MyFirstBatch.bat and double-click the file.
A Command Prompt window should open and display your message:
Hello! Your batch file is working.
Press any key to continue . . .
Press any key to close the window. The pause command keeps the window open long enough for you to read the output.
You can also right-click the batch file and select Open, depending on your Windows configuration. If your script requires administrator permissions, you may need to right-click it and select Run as administrator. Only do this when you understand the commands and trust the script.
For a basic message-display script, administrator access is unnecessary.
Step 6: Create a Batch File to Open Applications
You can do more than display messages. A batch file can also launch programs you use every day.
For example, enter this code into a new Notepad document:
@echo off
start “” notepad.exe
start “” calc.exe
exit
Save the file as OpenApps.bat, using All Files in the Save As dialog.
When you run it, Windows attempts to open Notepad and Calculator. The start command launches each application, while the empty quotation marks provide a window-title argument and help avoid issues when specifying program paths containing spaces. The exit command closes the script’s Command Prompt session.
The process is Notepad > Enter the commands > Save As > OpenApps.bat > Run.
You can adapt this script to launch other applications. For programs that aren’t available through a standard command name, you may need to specify the application’s full executable path.
Step 7: Create a Batch File to Make a Folder
Another practical example is using a batch file to create a folder automatically. This can be handy when setting up a workspace or organizing files.
Enter the following commands in Notepad:
@echo off
mkdir “%USERPROFILE%\Desktop\MyFolder”
echo Folder creation command completed.
pause
Save the file as CreateFolder.bat, making sure that the file type is set to All Files.
When you run the script, Windows attempts to create a folder named MyFolder on your Desktop. The %USERPROFILE% environment variable points to your Windows user profile, so the command doesn’t require you to type your account’s full folder path.
If the folder already exists, the command may report that it cannot create it. That’s normal and doesn’t mean the batch file itself is broken.
Before using folder-creation or file-management commands in larger scripts, check the target path carefully. A small path mistake can cause files to be created in an unexpected location.
Step 8: Edit an Existing Batch File
You don’t need to create a new file every time you want to change a command. You can edit an existing batch file directly.
Locate the file in File Explorer, right-click it, and select Show more options > Edit on Windows 11 if needed. On Windows 10, right-click the file and select Edit. The available menu options may vary by system configuration.
Notepad should open with your existing commands. Make the necessary changes, then select File > Save.
For example, you can replace the message in your first script or add another echo command on a new line.
Save your changes before running the file again. If the script is already running, close that instance and start it again to test the updated version.
When editing an unfamiliar batch file, read every command before executing it. Commands that delete files, change system settings, or modify large numbers of folders deserve particular attention.
Step 9: Troubleshoot Common Batch File Problems
If your batch file doesn’t work, check the filename first. A script saved with a .txt extension won’t run as a normal batch file. Enable file extensions in File Explorer and confirm that the filename ends in .bat.
Next, review the commands for typing errors. A missing quotation mark, incorrect path, or misspelled executable name can prevent part of the script from working.
If a window opens and closes too quickly, add pause to the end of the script. This lets you read any error messages before closing the window.
If a command fails because Windows can’t find a program, verify that the program is installed and that its executable path is correct. If a script needs elevated permissions, run it as an administrator only when appropriate.
Finally, remember that Windows security software may flag suspicious scripts. Don’t disable your antivirus simply to run a batch file. Review the commands and confirm that the script is trustworthy before proceeding.
FAQs
1. What is a batch file in Windows?
A batch file is a plain-text file containing commands that Windows executes in sequence. It usually uses the .bat extension and can automate repetitive tasks, launch programs, and perform file operations.
2. Can I create a batch file without programming knowledge?
Yes. You can create a basic batch file using Notepad and a few simple commands, such as echo, pause, and start. More complex automation may require additional command knowledge.
3. How do I run a batch file as an administrator?
Right-click the batch file and select Run as administrator, then approve the User Account Control prompt if it appears. Use this option only when the commands genuinely require elevated permissions.
4. Why is my batch file opening in Notepad instead of running?
The file may have been saved with a .txt extension, or its file association may have changed. Enable file extensions in File Explorer and verify that the filename ends in .bat. If the extension is correct, check the file association settings.
5. Can I run a batch file automatically when Windows starts?
Yes. You can place a suitable batch file in your Windows Startup folder so it runs when you sign in. Press Windows + R, type shell:startup, and press Enter to open the current user’s Startup folder. Add a shortcut to your batch file there. Be sure the script is safe and doesn’t perform unwanted actions during startup.
6. Are batch files safe to use?
Batch files are not inherently dangerous, but their commands can make significant changes to your system. A script may delete files, modify settings, or launch other programs. Review the commands before running an unfamiliar batch file, especially one downloaded from the internet.
Final Words
Creating a batch file in Windows is a straightforward way to automate everyday tasks without installing additional software. With Notepad, a few commands, and the correct .bat extension, you can create scripts that display messages, launch applications, and organize folders.
Start with a simple script, test it, and then gradually add more commands as you become comfortable with the process. Always verify file paths, save your changes, and understand what each command does before running it.
Whether you’re using Windows 11 or Windows 10, learning to create batch files can save time and make repetitive PC tasks easier to manage.