How to create and run a batch file on Windows 10
Batch files let you automate tasks, and in this guide, we'll show you how to use them on Windows 10.
On Windows 10, a batch file typically has a ".bat" extension, and it is a special text file that contains one or multiple commands that run in sequence to perform various actions with Command Prompt.
Although you can type commands manually to execute a particular task or change system settings on Windows 10, a batch file simplifies the work of having to re-type the commands, saving you time and avoiding mistakes.
You can also use other tools like PowerShell to write even more advanced scripts. However, running batch files in Command Prompt is still relevant for executing commands to change settings, automate routines, and launch apps or web pages on your computer.
This guide will walk you through the steps to create and run a batch file on Windows 10. Also, we will outline the steps to create advanced scripts and rum them automatically on schedule using the Task Scheduler.
How to create a batch file on Windows 10
The process of writing a batch file is not complicated. You only need Notepad or another text editor and some basic knowledge of typing commands in Command Prompt. These instructions will help you create a basic and advanced batch file to query system settings.
Create basic Windows 10 batch file
To create a basic batch file on Windows 10, use these steps:
Get the Windows Central Newsletter
All the latest news, reviews, and guides for Windows and Xbox diehards.
- Open Start.
- Search for Notepad and click the top result to open the text editor.
- Type the following lines in the text file to create a batch file:
@ECHO OFF
ECHO Hello World! Your first batch file was printed on the screen successfully.
PAUSE
The above script outputs the phrase, "Hello World! Your first batch file was printed on the screen successfully," on the screen.
- @ECHO OFF — Shows the message on a clean line disabling the display prompt. Usually, this line goes at the beginning of the file. (You can use the command without the "@" symbol, but it's recommended to include it to show a cleaner return.)
- ECHO — The command prints the text after the space on the screen.
- PAUSE — Allows the window to stay open after the command has been executed. Otherwise, the window will close automatically as soon as the script finishes executing. You can use this command at the end of the script or after a specific command when running multiple tasks and wanting to pause between each line.
- Click the File menu.
- Select the Save as option.
- Confirm a name for the script — for example, first_basic_batch.bat.
- Quick note: While batch files typically use the .bat file extensions, you can also find them using the .cmd or .btm file extensions.
Once you complete the steps, double-click the file to run it. Alternatively, you can use the steps below to learn how to run a batch file with Command Prompt, File Explorer, or Task Scheduler.
Create advanced Windows 10 batch file
To create an advanced Windows batch file with multiple commands, use these steps:
- Open Start.
- Search for Notepad and click the top result to open the text editor.
- Type the following lines in the text file to create a more advanced Windows 10 batch file:
@ECHO OFF
:: This batch file details Windows 10, hardware, and networking configuration.
TITLE My System Info
ECHO Please wait... Checking system information.
:: Section 1: Windows 10 information
ECHO ==========================
ECHO WINDOWS INFO
ECHO ============================
systeminfo | findstr /c:"OS Name"
systeminfo | findstr /c:"OS Version"
systeminfo | findstr /c:"System Type"
:: Section 2: Hardware information.
ECHO ============================
ECHO HARDWARE INFO
ECHO ============================
systeminfo | findstr /c:"Total Physical Memory"
wmic cpu get name
wmic diskdrive get name,model,size
wmic path win32_videocontroller get name
wmic path win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution
:: Section 3: Networking information.
ECHO ============================
ECHO NETWORK INFO
ECHO ============================
ipconfig | findstr IPv4ipconfig | findstr IPv6
START https://support.microsoft.com/en-us/windows/windows-10-system-requirements-6d4e9a79-66bf-7950-467c-795cf0386715
PAUSE
The above script runs each line to query a series of system details, and the result will be divided into three categories, including "WINDOWS INFO," "HARDWARE INFO," and "NETWORK INFO." Also, the "START" command will open the web browser in the official support page outlining the Windows 10 system requirements, which you can check against your information.
- @ECHO OFF — Shows the message on a clean line disabling the display prompt. Usually, this line goes at the beginning of the file.
- TITLE — Prints a custom name in the title bar of the console window.
- :: — Allows writing comments and documentation information. These details are ignored when the system runs the batch file.
- ECHO — Prints the text after the space on the screen.
- START — Opens an app or website with the default web browser.
- PAUSE — Tells the console window to stay open after running the command. If you do not use this option, the window will close automatically as soon as the script finishes executing.
- Click the File menu.
- Select the Save as option.
- Type a name for the script — for example, first_advanced_batch.bat.
After you complete the steps, double-click the .bat file to run it or use the steps below to execute the script with Command Prompt, File Explorer, or Task Scheduler.
Create actionable Windows 10 batch file
You can also write batch scripts for any task that does not require user interaction. For instance, to map a network drive, install an application, change system settings, and more.
To create a non-interactive batch file on Windows 10, use these steps:
- Open Start.
- Search for Notepad and click the top result to open the text editor.
- Type the following command to map a network drive in the text file: net use z: \\PATH-NETWORK-SHARE\FOLDER-NAME /user:YOUR-USERNAME YOUR-PASSWORD
In the command, replace the "\\PATH-NETWORK-SHARE\FOLDER-NAME" for the folder network path to mount on the device and "YOUR-USERNAME YOUR-PASSWORD" with the username and password that authenticates access to the network share.
This example maps a network folder as a drive inside File Explorer using the "Z" drive letter: net use z: \\10.1.4.174\ShareFiles
- Quick note: If you are accessing the files from another computer that uses a specific username and password, do not forget to use the /user: option with the correct credentials.
- Click the File menu.
- Select the Save as option.
- Confirm a name for the script — for example, mount-z-network-drive.bat.
Once you complete the steps, the batch file will map the network folder without opening a Command Prompt window.
We only demonstrate a script with a single command, but you can include as many as you like, as long as you write them one per line.
How to run a batch file on Windows 10
Windows 10 has at least three ways to write batch files. You can run them on-demand using Command Prompt or File Explorer. You can configure the script using the Task Scheduler app to run it on schedule. Or you can save the batch files in the "Startup" folder to let the system run them as soon as you sign into the account.
Run batch file on-demand
If you want to run a script on-demand, you can use File Explorer or Command Prompt.
Command Prompt
To run a script file with Command Prompt on Windows 10, use these steps:
- Open Start.
- Search for Command Prompt, right-click the top result, and select the Run as administrator option.
- Type the following command to run a Windows 10 batch file and press Enter: C:\PATH\TO\FOLDER\BATCH-NAME.bat
In the command, make sure to specify the path and name of the script.
This example runs the batch file located in the "scripts" folder inside the "Downloads" folder: C:\Users\UserAccount\Downloads\first_basic_batch.bat
After you complete the steps, the console will return the results, and the window won't close even if the script does not include the "PAUSE" command since you are invoking the script from within a console session that was already open.
File Explorer
To run a batch file with File Explorer, use these steps:
- Open File Explorer.
- Browse to the folder with the batch file.
- Double-click the script file to run it.
- (Optional) If a command in the batch file requires administrator privileges, you will have to run the script as an admin by right-clicking the file and selecting the Run as administrator option.
- Click the Yes button
Once you complete the steps, the script will run each command in sequence, displaying the results in the console window.
Run batch files on startup
Windows 10 also features a known folder called "Startup," which the system checks every time it starts to run applications, shortcuts, and scripts automatically without the need for extra configuration.
To run a script on the Windows 10 startup, use these steps:
- Open File Explorer.
- Open the folder containing the batch file.
- Right-click the batch file and select the Copy option.
- Use the Windows key + R keyboard shortcut to open the Run command.
- Type the following command: shell:startup
- Click the OK button.
- Click the Paste option from the "Home" tab in the Startup folder. (Or click the Paste shortcut button to create a shortcut to the batch file.)
After you complete the steps, the batch file will execute automatically every time you log into your account.
Run batch file with Task Scheduler
To use Task Scheduler to run the batch file automatically at a specific time, use these steps:
- Open Start.
- Search for Task Scheduler and click the top result to open the app.
- Right-click the "Task Scheduler Library" branch and select the New Folder option.
- Confirm a name for the folder — for example, MyScripts.
- Quick note: You don't need to create a folder, but keeping the system and your tasks separate is recommended.
- Click the OK button.
- Expand the "Task Scheduler Library" branch.
- Right-click the MyScripts folder.
- Select the Create Basic Task option.
- In the "Name" field, confirm a name for the task — for example, SystemInfoBatch.
- (Optional) In the "Description" field, write a description for the task.
- Click the Next button.
- Select the Monthly option.
- Quick note: Task Scheduler lets you choose from different triggers, including a specific date, during startup, or when a user logs in to the computer. In this example, we will select the option to run a task every month, but you may need to configure additional parameters depending on your selection.
- Click the Next button.
- Use the "Start" settings to confirm the day and time to run the task.
- Use the "Monthly" drop-down menu to pick the months of the year to run the task.
- Use the "Days" or "On" drop-down menu to confirm the days to run the task.
- Click the Next button.
- Select the Start a program option to run the batch file.
- In the "Program/script" field, click the Browse button.
- Select the batch file you want to execute.
- Click the Finish button.
Once you complete the steps, the task will run the script during the configured time and date or action.
The above instructions are meant to schedule only a basic task. You can use these instructions to create a more customizable task with the Task Scheduler.
This guide focuses on Windows 10, but the same steps will also work for older versions, including Windows 8.1 and 7. Also, you can refer to these instructions if you have Windows 11 installed on your computer.
More Windows resources
For more helpful articles, coverage, and answers to common questions about Windows 10 and Windows 11, visit the following resources:
Mauro Huculak has been a Windows How-To Expert contributor for WindowsCentral.com for nearly a decade and has over 15 years of experience writing comprehensive guides. He also has an IT background and has achieved different professional certifications from Microsoft, Cisco, VMware, and CompTIA. He has been recognized as a Microsoft MVP for many years.