(Image credit: Windows Central)
On Windows 10, a batch file typically has a “.bat” extension, and it is a special text file that includes ane or multiple commands that run in sequence to perform various actions with Command Prompt.
Although you lot can blazon commands manually to execute a particular task or modify system settings on Windows 10, a batch file simplifies the work of having to re-type the commands, saving yous time and fugitive mistakes.
Y’all tin can also apply other tools like PowerShell to write even more advanced scripts. However, running batch files in Command Prompt is nevertheless relevant to execute commands to change settings, automate routines, and launch apps or web pages on your device.
In this Windows 10 guide, we will walk you through the steps to create and run a batch file. As well, we will outline the steps to create advanced scripts and rum them automatically on schedule using the Job Scheduler.
- How to create a batch file on Windows 10
- How to run a batch file on Windows 10
How to create a batch file on Windows 10
The process of writing a batch file is straightforward. You but demand Notepad or some other text editor and some bones knowledge typing commands in Command Prompt. These instructions will assistance you create a basic and advanced batch file to query system settings.
Create basic Windows 10 batch file
To create a bones batch file on Windows 10, use these steps:
- Open up
Commencement. - Search for
Notepad
and click the meridian result to open the text editor. - Type the following lines in the text file to create a batch file:
@ECHO OFFECHO Hello Earth! Your first batch file was printed on the screen successfully.Suspension
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. Unremarkably, this line goes at the offset of the file. (You tin apply the command without the “@” symbol, but it’s recommended to include information technology to bear witness a cleaner return.) -
Repeat —
The command prints the text after the infinite on the screen. -
Suspension —
Allows the window to stay open afterward the control has been executed. Otherwise, the window will shut automatically every bit soon as the script finishes executing. You tin use this command at the end of the script or after a specific control when running multiple tasks and want to pause betwixt each line.
-
@ECHO OFF —
- Click the
File
menu. - Select the
Save every bit
option. - Confirm a name for the script — for example,
first_basic_batch.bat.Quick note:
While batch files typically employ the
.bat
file extensions, you tin also notice them using the
.cmd
or
.btm
file extensions.
Once you lot consummate the steps, double-click the file to run it. Alternatively, you lot can use the steps below to larn the dissimilar ways you can run a batch file with Command Prompt, File Explorer, or Job Scheduler.
Create advanced Windows 10 batch file
To create an avant-garde Windows batch file with multiple commands, use these steps:
- Open
Offset. - Search for
Notepad
and click the top result to open up the text editor. - Type the following lines in the text file to create a more avant-garde Windows 10 batch file:
@Echo OFF :: This batch file details Windows ten, hardware, and networking configuration.Championship My System InfoECHO Please look... Checking system data.:: Department 1: Windows x informationECHO ==========================Echo WINDOWS INFOECHO ============================systeminfo | findstr /c:"OS Name"systeminfo | findstr /c:"Bone Version"systeminfo | findstr /c:"System Type":: Department two: Hardware information.Echo ============================Repeat HARDWARE INFOECHO ============================systeminfo | findstr /c:"Total Physical Memory"wmic cpu go namewmic diskdrive become proper noun,model,sizewmic path win32_videocontroller get namewmic path win32_VideoController become CurrentHorizontalResolution,CurrentVerticalResolution:: Section three: Networking data.Echo ============================Echo NETWORK INFOECHO ============================ipconfig | findstr IPv4ipconfig | findstr IPv6START https://support.microsoft.com/en-u.s./windows/windows-x-system-requirements-6d4e9a79-66bf-7950-467c-795cf0386715PAUSE
The higher up script runs each line to query a serial of system details, and the result volition be divided into three categories, including “WINDOWS INFO,” “HARDWARE INFO,” and “NETWORK INFO.” Also, the “START” command volition open the web browser in the official support folio outlining the Windows x organization requirements, which you lot can check against your information.-
@Repeat OFF —
Shows the message on a clean line disabling the display prompt. Ordinarily, this line goes at the starting time of the file. -
TITLE —
Prints a custom proper name in the championship bar of the panel window. -
:: —
Allows writing comments and documentation information. These details are ignored when the system runs the batch file. -
Echo —
Prints the text later on the space on the screen. -
Outset —
Opens an app or website with the default web browser. -
PAUSE —
Tells the console window to stay open after running the control. If you do not use this option, the window volition close automatically as presently every bit the script finishes executing.
-
@Repeat OFF —
- Click the
File
bill of fare. - Select the
Save every bit
option. - Type a name for the script — for example,
first_advanced_batch.bat.
Subsequently you consummate the steps, double-click the
.bat
file to run it or utilise the steps below to execute the script with Command Prompt, File Explorer, or Task Scheduler.
Create actionable Windows 10 batch file
Y’all tin besides write batch scripts for whatsoever task that does not require user interaction. For instance, to map a network drive, install an application, change organisation settings, and more.
To create a non-interactive batch file on Windows 10, use these steps:
- Open
Outset. - Search for
Notepad
and click the top result to open up the text editor. - Type the post-obit command to map a network drive in the text file:
internet 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-Countersign
with the username and password that authenticates access to the network share.This case maps a network folder equally a bulldoze within File Explorer using the “Z” drive letter:net use z: \\10.1.4.174\ShareFiles
Quick note:
The screenshot includes the “interruption” control, but this is non required. It was added in this example to have a screenshot of the console. If yous are accessing the files from another reckoner that uses a specific username and password, practise not forget to use the
/user:
pick with the correct credentials.
- Click the
File
carte. - Select the
Save equally
option. - Confirm a name for the script — for example,
mount-z-network-drive.bat.
One time you complete the steps, the batch file will map the network folder without opening a Command Prompt window.
Nosotros just demonstrate a script with a single command, but y’all can include as many as you like, every bit long as you write them one per line.
How to run a batch file on Windows x
Windows 10 has at least 3 ways to write batch files. You tin can run them on-demand using Command Prompt or File Explorer. Using the Task Scheduler app, you can configure the script to run it on schedule. Or you tin save the batch files in the “Startup” folder to let the arrangement run them every bit shortly as yous sign into the account.
Run batch file on-demand
If you desire to run a script on-demand, you lot tin can use File Explorer or Command Prompt.
Control Prompt
To run a script file with Command Prompt on Windows 10, use these steps:
- Open up
Commencement. - Search for
Command Prompt, right-click the top result, and select the
Run as ambassador
option. - Type the following command to run a Windows ten batch file and press
Enter:C:\PATH\TO\FOLDER\BATCH-Proper name.bat
In the control, make sure to specify the path and proper name of the script.This instance runs the batch file located in the “scripts” folder inside the “Downloads” folder:C:\Users\UserAccount\Downloads\first_basic_batch.bat
After y’all complete the steps, the console will return the results, and the window won’t close even if the script does non include the “PAUSE” command since you lot 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 up
File Explorer. - Browse to the folder with the batch file.
- Double-click the script file to run information technology.
- (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 control in sequence, displaying the results in the console window.
Run batch files on startup
Windows ten also features a known binder chosen “Startup,” which the system checks every fourth dimension it starts to run applications, shortcuts, and scripts automatically without the need for actress configuration.
To run a script on the Windows 10 startup, use these steps:
- Open
File Explorer. - Open to the folder containing the batch file.
- Right-click the batch file and select the
Copy
option. - Use the
Windows fundamental + R
keyboard shortcut to open the
Run
command. - Type the following command:
shell:startup
- Click the
OK
button. - Click the
Paste
option from the “Abode” tab in the
Startup
folder. (Or click the
Paste shortcut
button to create a shortcut to the batch file.)
After you lot consummate the steps, the batch file will execute automatically every time you log into your account.
Run batch file with Task Scheduler
To apply Task Scheduler to run the batch file automatically at a specific time, use these steps:
- Open
Start. - Search for
Task Scheduler
and click the pinnacle result to open the app. - Right-click the “Chore Scheduler Library” co-operative and select the
New Folder
option. - Confirm a name for the folder — for case,
MyScripts.Quick note:
You don’t need to create a folder, just keeping the organisation and your tasks divide is recommended. - Click the
OK
button. - Expand the “Task Scheduler Library” branch.
- Correct-click the
MyScripts
binder. - Select the
Create Basic Task
option.
- In the “Proper noun” field, confirm a name for the chore — for example,
SystemInfoBatch. - (Optional) In the “Description” field, write a clarification for the task.
- Click the
Side by side
button. - Select the
Monthly
option.Quick note:
Task Scheduler lets y’all cull 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, simply you may need to configure additional parameters depending on your selection.
- Click the
Next
button. - Employ the “Start” settings to confirm the day and time to run the task.
- Use the “Monthly” drib-down menu to pick the months of the yr to run the task.
- Employ the “Days” or “On” drop-down card to confirm the days to run the task.
- Click the
Next
button. - Select the
Start a programme
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
End
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 bones chore. You can use these instructions to create a more than customizable job with the Chore Scheduler.
This guide focuses on Windows 10, but the aforementioned steps will also work for older versions, including Windows viii.1 and Windows 7. Also, you can refer to these instructions if you lot have Windows 11 installed on your estimator.
More Windows resources
For more helpful articles, coverage, and answers to mutual questions nearly Windows x and Windows 11, visit the following resource:
- Windows 11 on Windows Key — All you need to know
- Windows eleven help, tips, and tricks
- Windows 10 on Windows Primal — All you need to know
Mauro Huculak is technical writer for WindowsCentral.com. His primary focus is to write comprehensive how-tos to help users get the virtually out of Windows 10 and its many related technologies. He has an IT background with professional certifications from Microsoft, Cisco, and CompTIA, and he’due south a recognized member of the Microsoft MVP community.
Source: https://www.windowscentral.com/how-create-and-run-batch-file-windows-10