5 Best Ways to Create a Batch file on Windows 11
Mastering Batch File Creation on Windows 11: The Top 5 Methods

Users of Windows 11 may need to create a batch file because of the need to perform repetitive tasks. A batch file is a text file with a “.bat” extension. It contains a series of commands that the system can execute to complete different tasks via the Command Prompt.
A batch file can automate tasks, save time, and simplify processes. While PowerShell allows for more comprehensive scripts, batch files crafted for Command Prompt remain beneficial and easier to use for a variety of tasks.
1. Create a basic batch file
Creating a basic batch file is relatively simple. You may use any text editor like Notepad to create the file. Use the following steps to achieve this:
- Hold down the Windows and S keys simultaneously, type notepad in the search field, and hit Enter.
- When Notepad opens, type
@echo off
and move to the next line by hitting Enter. - The command above disables the entire script display, implying you will not see the script while running.
- Then, type title followed by the title of your batch file, and hit Enter.
- Afterward, type echo followed by the text you want to be viewable on the output display, and hit Enter.
- Then, type pause and hit Enter. This command depicts the end of the batch file, and also keeps the Command Prompt window open that would normally close upon successful execution.
- Click the File option at the top-left corner of the Notepad window and select the Save as option.
- Lastly, name the batch file correctly with a BAT extension.
i.e..bat
e.g. article.bat. - When you want to run the batch file, locate the batch file and double-click on it. A Command Prompt window will launch, displaying the batch file output.
2. Access network drives and folders
You can also create a batch file to access network drives and folders. Here are the steps on how to create a batch file to access network drives and folders on Windows 11:
- Hold down the Windows and S keys simultaneously, type notepad in the search field, and hit Enter.
- When the Notepad opens, enter the following code and replace the letter
F
with your driver letter:Echo Create new F: drive mapping
- Then, enter the following command and replace the Network path with the path you intend to map to:
@net use F: \Network path /persistent: yes
- You may repeat the process if you intend to add multiple drives.
- Then, enter the following lines:
: exit
@pause - Lastly, click on File, select Save as, correctly name the file with a
.bat
extension, select All files for Save as type, and then click Save. - When you want to run the batch file, locate it and double-click on it. A Command Prompt window will launch, displaying the batch file output.
3. Add user inputs
Adding user input to a batch file lets you customize the actions taken by the batch file. For instance, you could create a batch file to prompt a user for the name of a file to copy and then copy that file to a new location. Follow these steps to do that:
- Hold down the Windows and S keys, type notepad in the search field, and hit Enter.
- Enter the following script when the Notepad opens:
@echo off
: start
set /p input = Enter the Name:
echo %input% We are thrilled to welcome you to the event!
pause
go to start - You may change the Enter the Name instruction and the customized message to match your task and preferences.
- Lastly, click on File, select Save as, correctly name the file with a
.bat
extension, select All files for Save as type, and then click Save. - When you want to run the batch file, locate it and double-click on it. A Command Prompt window will launch, displaying the batch file output.
4. Automate repetitive tasks
Creating a batch file to automate repetitive tasks can save time and effort. It can help you save time, reduce errors, increase productivity, and improve consistency. Here is how to create the batch file:
Here, we will show you how we automated opening frequently used apps on our computer.
- Hold down the Windows and S keys, type notepad in the search field and, hit Enter.
- The script below opens Google Chrome, Word, Slack, and ShareX:
@echo off
cd "C:\Program Files\Google\Chrome\Application\chrome.exe"
start chrome.exe
start – "C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE"
cd "C:\Program Files\ShareX\ShareX.exe"
start ShareX.exe
Exit - Replace the app path with the path you intend to open.
- Finally, click on File, select Save as, correctly name the file with a
.bat
extension, select All files for Save as type, and then click Save.
5. Edit lines of code with the command window
Creating a batch file on Windows 11 to edit lines of code can help save time, reduce errors, and increase consistency. It can also make repeating tasks easier and learn more about the command line. The script in this solution can help you replace lines in a simple code. Follow the steps below:
- Hold down the Windows and S keys simultaneously, type notepad in the search field and hit Enter.
- Assuming a file named code.txt has oldtext mentioned several times, and you intend to replace it with newtext, use the following script:
@echo off
setlocal enabledelayedexpansion
set "inputFile=code.txt"
set "outputFile=code_modified.txt"
set "oldText=oldtext" set "newText=newtext"
if not exist "%inputFile%" (
echo Input file not found.
exit /b
)
(
for /f "usebackq delims=" %%a in ("%inputFile%") do (
set "line=%%a"
set "line=!line:%oldText%=%newText%!"
echo !line!
)
) > "%outputFile%"
echo Lines with '%oldText%' replaced by '%newText%' have been written to '%outputFile%'.
endlocal - Replace code.txt with your file name and oldtext and newtext with the lines you intend to use.
- Lastly, click on File, select Save as, correctly name the file with a
.bat
extension, select All files for Save as type, and then click Save. - When you want to run the batch file, locate it and double-click on it. A Command Prompt window will launch, displaying the batch file output.
In conclusion, you can create a batch file to enhance your productivity and efficiency on Windows 11. With various methods available, you can choose the approach that best suits your needs and technical expertise.
Remember, batch files can automate repetitive tasks, execute multiple commands simultaneously, and simplify complex operations. Whether you’re a beginner or a pro, the step-by-step instructions in this article will help you to create batch files and unlock the full potential of your Windows 11 system.