How to Create and Run a Batch File on Windows 10
Batch files are a convenient way to automate tasks on your computer, and in this guide, we’ll demonstrate how to create and run them on Windows 10. A batch file is a special text file with a “.bat” extension containing a sequence of commands to be executed by the Command Prompt.
While you can manually type commands to perform tasks or modify system settings on Windows 10, batch files streamline this process by saving time and reducing the risk of errors. Additionally, you can use tools like PowerShell for more complex scripts, but batch files remain useful for many automation tasks.
This guide covers the steps to create and run batch files on Windows 10, including creating advanced scripts and scheduling them using Task Scheduler.
Creating a Batch File on Windows 10
Creating a batch file is simple and requires only a text editor like Notepad and basic command-line knowledge. Follow these steps to create both basic and advanced batch files.
Create a Basic Windows 10 Batch File
To create a basic batch file, follow these steps:
- Open Notepad:
- Open Start, search for Notepad, and click the top result to open the text editor.
- Type the following lines:
@ECHO OFF ECHO Hello World! Your first batch file was printed on the screen successfully. PAUSE
@ECHO OFF
ensures the commands are executed without being displayed.ECHO
prints the specified text to the screen.PAUSE
keeps the window open after execution.
- Save the File:
- Click
File
>Save As
. - Name the script, for example,
first_basic_batch.bat
. - Ensure the file extension is
.bat
.
Double-click the saved file to run it. Alternatively, you can run it using Command Prompt, File Explorer, or Task Scheduler.
Create an Advanced Windows 10 Batch File
To create an advanced batch file with multiple commands, follow these steps:
- Open Notepad:
- Open Start, search for Notepad, and click the top result.
- Type the following lines:
@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 IPv4 ipconfig | findstr IPv6 START https://support.microsoft.com/en-us/windows/windows-10-system-requirements-6d4e9a79-66bf-7950-467c-795cf0386715 PAUSE
- Commands are categorized into sections: Windows info, hardware info, and network info.
START
opens the specified URL in the default web browser.
- Save the File:
- Click
File
>Save As
. - Name the script, for example,
first_advanced_batch.bat
.
Double-click the file to run it or use Command Prompt, File Explorer, or Task Scheduler.
Create an Actionable Windows 10 Batch File
For tasks that don’t require user interaction, such as mapping a network drive, follow these steps:
- Open Notepad:
- Open Start, search for Notepad, and click the top result.
- Type the following command:
net use z: \\PATH-NETWORK-SHARE\FOLDER-NAME /user:YOUR-USERNAME YOUR-PASSWORD
- Replace
\\PATH-NETWORK-SHARE\FOLDER-NAME
with the network path andYOUR-USERNAME YOUR-PASSWORD
with the appropriate credentials.
- Replace
- Save the File:
- Click
File
>Save As
. - Name the script, for example,
mount-z-network-drive.bat
.
The batch file will map the network folder when executed, without opening a Command Prompt window.
Running a Batch File on Windows 10
There are several ways to run batch files on Windows 10: on-demand, at startup, or on a schedule.
Run Batch File On-Demand
You can run a batch file on-demand using Command Prompt or File Explorer.
Using Command Prompt
- Open Command Prompt:
- Open Start, search for Command Prompt, right-click the top result, and select
Run as administrator
.
- Run the Batch File:
- Type the command:
C:\PATH\TO\FOLDER\BATCH-NAME.bat
- Replace with the actual path and name of your batch file.
Using File Explorer
- Open File Explorer:
- Browse to the folder containing the batch file.
- Run the File:
- Double-click the batch file.
- (Optional) Right-click and select
Run as administrator
if required.
Run Batch Files on Startup
To run a batch file at startup, follow these steps:
- Copy the Batch File:
- Right-click the batch file and select
Copy
.
- Open the Startup Folder:
- Press
Windows key + R
, typeshell:startup
, and clickOK
.
- Paste the Batch File:
- Paste the file or create a shortcut to the batch file in the Startup folder.
Run Batch File with Task Scheduler
To run a batch file using Task Scheduler:
- Open Task Scheduler:
- Open Start, search for Task Scheduler, and click the top result.
- Create a New Task:
- Right-click
Task Scheduler Library
, selectNew Folder
, name it (e.g.,MyScripts
), and clickOK
.
- Configure the Task:
- Right-click the new folder, select
Create Basic Task
. - Follow the wizard to name the task, set the trigger, and select the batch file to run.
- Click
Finish
.
The task will execute the batch file based on the configured schedule.
These steps ensure you can create and run batch files efficiently, automating various tasks on Windows 10. This guide is also applicable to older versions like Windows 8.1 and 7, and it can be referenced for Windows 11.