Вы находитесь на странице: 1из 23

1/3/2020 How to create and run a batch file on Windows 10

 

Top-rated option: Save 49% on 15 months of ExpressVPN

We may earn a commission for purchases using our links. Learn more.

BATCH FOR BEGINNERS

How to create and run a batch file on Windows 10


Stop wasting your time typing commands manually and use a batch file instead — Here's how on
Windows 10.

MAURO HUCULAK 26 Nov 2019 

    

Source: Windows Central

On Windows 10, a batch file is a special kind of text file that typically has a .bat extension,
which can include one or multiple commands that Command Prompt can understand and run
https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 1/23
1/3/2020 How to create and run a batch file on Windows 10

in sequence to perform various actions.


 

Usually, you can input commands manually to perform a particular task, but a batch file
simplifies the work of retyping commands, saving you time.

Also, even though, there are other tools, such as PowerShell, that write more advanced
scripts, using batch files with Command Prompt is a convenient option when you need to run
commands to change system settings, automate routines, and launch apps or websites.

In this Windows 10 guide, we walk you through the steps to get started creating and running
your first batch file on your computer.

window 7 notebook
$0 Get latest price now
Alibaba.com

 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 (script or batch script) file is easy. You only need a text editor
and some knowledge using Command Prompt. In the steps below, we detail the steps for
creating a simple and advanced batch file, as well as the steps to write a script to change the
system settings.

 Buy one iPhone 11, get one for FREE at Verizon


Limited Time Offer

Creating simple batch file

To create a simple batch file on Windows 10, use these steps:

1. Open Start.
2. Search for Notepad, and click the top result to launch the app.

3. Type the following lines to create a simple batch file:

@ECHO OFF
ECHO Congratulations! Your first batch file executed successfully.
PAUSE
https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 2/23
1/3/2020 How to create and run a batch file on Windows 10

 

Source: Windows Central

The above script outputs the phrase, "Congratulations! Your first batch file executed
successfully" on the screen.

    

Source: Windows Central

 @ECHO OFF — Turns off the display prompt to show only the message on a clean
line. Usually, this particular line goes at the beginning of the file. (You can use this
command without "@," but the symbol hides the command being executed for a
cleaner output.)
 ECHO — Prints the desired text on the screen.
 PAUSE — Prevents the console window from closing after executing the command.
You can use this command at the end of the script or after a specific command when
running multiple tasks, and you want to pause between them.

4. Click the File menu.

5. Select the Save as option.

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 3/23
1/3/2020 How to create and run a batch file on Windows 10

6. Type a name for the script — for example, first_simple_batch.bat. 

Quick note: While batch files typically use the .bat file extensions, you may also see
scripts using the .cmd or .btm file extensions.

Once you complete the steps, you can double-click the file to run it, or you can use the steps
below to learn the different ways to execute a batch file on Windows 10.

Creating advanced batch file

To create an interactive batch file that executes multiple commands, use these steps:

1. Open Start.

2. Search for Notepad, and click the top result to launch the app.
3. Type the following lines to create a complex batch file:

@ECHO OFF
:: This batch file reveals OS, hardware, and networking

configuration.    
TITLE My System Info
ECHO Please wait... Checking system information.
:: Section 1: OS information.
ECHO ============================
ECHO OS 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
:: Section 3: Networking information.
ECHO ============================

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 4/23
1/3/2020 How to create and run a batch file on Windows 10

 ECHO NETWORK INFO 


ECHO ============================
ipconfig | findstr IPv4
ipconfig | findstr IPv6
PAUSE

    

Source: Windows Central

The above batch script will run a series of commands to query different system
information that is grouped into three different categories, including OS INFO,
HARDWARE INFO, and NETWORK INFO.

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 5/23
1/3/2020 How to create and run a batch file on Windows 10

 

Source: Windows Central

 @ECHO OFF — Turns off the display prompt to show only the message on a clean
line. Usually,
 this particular
line goes at the beginning
 of the file.
(You can use this 
command without "@," but the symbol hides the command being executed for a
cleaner output.)
 TITLE — Displays a custom name in the title bar of the console.
 :: — Allows you to add comments and documentation information, which are ignored
when the batch file runs.
 ECHO — Prints the text on the screen.
 PAUSE — Prevents the console window from closing after executing the command.
You can use this command at the end of the script or after a specific command when
running multiple tasks, and you want to pause between them.

4. Click the File menu.


5. Select the Save as option.
6. Type a name for the script — for example, first_advanced_batch.bat.

After you complete these steps, you can run the script double-clicking the .bat file, or you ca
use the steps below to learn the different ways to execute a batch on Windows 10.

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 6/23
1/3/2020 How to create and run a batch file on Windows 10

Creating
 actionable batch file 

You're not limited to showing information on a Windows 10 console. You can also write non-
interactive batch files to perform virtually any task. For instance, to write a batch file that runs
a specific command without the need for user interaction, use these steps:

1. Open Start.

2. Search for Notepad, and click the top result to launch the app.
3. Copy and paste the following command:

net use z: \\PATH-NETWORK-SHARE\FOLDER-NAME /user:YOUR-USERNAME


YOUR-PASSWORD

    

Source: Windows Central

The above command is just an ordinary command that maps a network folder as a drive
on File Explorer using the "Z" drive letter.

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 7/23
1/3/2020 How to create and run a batch file on Windows 10

 

Source: Windows Central

4. Click the File menu.


5. Select the Save as option.
6. Type a name for the script — for example, map-z-drive.bat.

Once you complete the steps, when you run the batch file, the command will map a shared
network folder with the settings, you specified without the need to open Command Prompt.
Although we only specified one command in the file, you can include as many commands as
you like, as long
 as you write oneper line.   

How to run a batch file on Windows 10


On Windows 10, there are a least three ways to run a batch file. You can run a batch on-
demand (using File Explorer or Command Prompt). You can create a scheduled task using
Task Scheduler. Or you can place the script in the "Startup" folder to run it every time you sig
in to your computer.

Running batch file on-demand

When you need to run a batch file on-demand, you can use File Explorer or Command
Prompt.

File Explorer

To run a batch file using File Explorer, use these steps:

1. Open File Explorer.

2. Navigate to the folder with the script.


3. Double-click the batch file to run it.

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 8/23
1/3/2020 How to create and run a batch file on Windows 10

 

Source: Windows Central

If you're executing a command that requires administrator privileges, you'll need to run th
    
script as an admin by right-clicking the batch file and selecting the Run as administrato
option, and clicking the Yes button.

After you complete the steps, the batch will run each command in sequence displaying the
results on the screen.

Command Prompt

To run a batch file from Command Prompt, use these steps.

1. Open Start.
2. Search for Command Prompt, right-click the top result, and select the Run as
administrator option.
3. Type the path and the name of the batch file and press Enter:

C:\PATH\TO\FOLDER\BATCH-NAME.bat

For example, the following command runs the batch file located in the user's "batch"
folder inside the "Downloads" folder:

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 9/23
1/3/2020 How to create and run a batch file on Windows 10

 C:\Users\user\Downloads\batch\first_simple_batch.bat 

Source: Windows Central

Once you complete the steps, the output will display on the screen regardless of the script
containing the "PAUSE" command or not.

    
Running batch file on scheduled

To schedule a batch file on Windows 10, you'll need to use the Task Scheduler with these
steps:

1. Open Start.
2. Search for Task Scheduler, and click the top result to open the app.
3. Right-click the "Task Scheduler Library" branch and select the New Folder option.
4. Type a name for the folder — for example, MyScripts.

Quick note: It's not necessary to create a folder, but it's recommended to organize your
tasks.

5. Click the OK button.

6. Expand the "Task Scheduler Library" branch.


7. Right-click the MyScripts folder.
8. Select the Create Basic Task option.

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 10/23
1/3/2020 How to create and run a batch file on Windows 10

 

Source: Windows Central

9. In the "Name" field, type a short descriptive name for the task — for example,
SystemInfoBatch.

    

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 11/23
1/3/2020 How to create and run a batch file on Windows 10

 

    

Source: Windows Central

10. (Optional) In the "Description" field, create a description for the task.
11. Click the Next button.

12. Select the Monthly option.

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 12/23
1/3/2020 How to create and run a batch file on Windows 10

 

    

Source: Windows Central

Task Scheduler allows you to select from a number of triggers, including on a specific
date, during startup, or when you or a particular user signs in to the computer. Depending
on your requirements, you'll need to configure additional parameters. In this case, we're
selecting the option to run a task every month.

13. Click the Next button.


14. Using the "Start" settings, specify the day and time when the task should start running.
15. Use the "Monthly" drop-down menu to pick the months of the year that you want to run
the task.

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 13/23
1/3/2020 How to create and run a batch file on Windows 10

 

    

Source: Windows Central

16. Use the "Days" or "On" drop-down menu to specify the days that the task will run.

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 14/23
1/3/2020 How to create and run a batch file on Windows 10

 

    

Source: Windows Central

17. Click the Next button.


18. Select the Start a program option to run the batch file.

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 15/23
1/3/2020 How to create and run a batch file on Windows 10

 

    

Source: Windows Central

19. In the "Program/script" field, specify the path for the batch file.

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 16/23
1/3/2020 How to create and run a batch file on Windows 10

 

    

Source: Windows Central

20. Click the Finish button.

Once you complete the steps, the task will be saved, and it'll run the batch file on the
schedule you specified.

These instructions cover the steps to create a basic task. If you want to create a more
customizable task, use this guide.

Running batch files on startup

Alternatively, if you want to run a batch file every time that you sign in to your device, use
these easy steps:

1. Open File Explorer.


2. Navigate to the folder that contains the batch file.
3. Right-click the file and select the Copy option.
4. Use the Windows key + R keyboard shortcut to open the Run command
https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 17/23
1/3/2020 How to create and run a batch file on Windows 10

5. Type the following command, and click the OK button: 

shell:startup

Source: Windows Central

6. Click the Paste option from the "Home" tab in the Startup folder. (Or you can click the
Paste shortcut button to create a shortcut to the batch file.)

    

Source: Windows Central

7. Sign out of your Windows 10 account.


8. Sign back into your account.

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 18/23
1/3/2020 How to create and run a batch file on Windows 10

After you complete the steps, every time you sign in to your account, the batch file will
 
automatically execute in sequence the commands you wrote.

We're focusing this guide on Windows 10, but the ability to use batch files has been around
for many years, which means that you can refer to these instructions if you're still using
Windows 8.1 or Windows 7.

More Windows 10 resources

For more helpful articles, coverage, and answers to common questions about Windows 10,
visit the following resources:

 Windows 10 on Windows Central – All you need to know

 Windows 10 help, tips, and tricks

 Windows 10 forums on Windows Central

We may earn a commission for purchases using our links. Learn more.

SOME CRINGE. SOME COOL.


Looking back at a decade of woeful, weird, and wonderful Microsoft ads
  
Microsoft has had its ups and downs when it comes to marketing. As part of the end-of-year festivities, I  
thought it might be entertaining to look back at some of the wacky, weird, and wonderful ads Microsoft has
put out over the years.

GAMES. MOVIES. HARDWARE!


Best ways to spend that Xbox Gift Card you received this Holiday Season
Did you receive an Xbox gift card this holiday season? Here are some suggestions on how to spend it!

IT'S BEEN A GOOD YEAR


We look back at the top PC hardware and accessories of 2019
2019 is in the books and all told it's been a strong year for PC fans. We've seen such a remarkable amount
of incredible hardware and accessories launched, be that high-end Ultrabooks, gaming laptops, mice,
keyboards, headsets, even software. Here's what I enjoyed the most from the past 12-months.

HONEY I SHRUNK THE COMPUTER!


These are the best PC sticks for when you're on the move
Instant computer, just add a screen! That’s the general idea of the ultra-portable PC Compute Sticks, but it
can be hard to know which one you want. Relax, we’ve got you covered.

 Help & How To Windows 10

 View Comments (3)


https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 19/23
1/3/2020 How to create and run a batch file on Windows 10

 

    

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 20/23
1/3/2020 How to create and run a batch file on Windows 10

 

We may earn a commission for purchases using our links. Learn more.

🎆🎇🎇🎆

Celebrate New Year's with these free Windows 10 wallpapers


SEAN ENDICOTT 30 Dec 2019 

    

Source: Microsoft

What you need to know


 Microsoft released several free wallpaper packs.
 Many of the new themes and wallpaper packs celebrate New Year's.
 They're available now, just in time for the new year.

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 21/23
1/3/2020 How to create and run a batch file on Windows 10

M

icrosoft released several free wallpapers, and they're just in time for New Year's via 
OnMSFT. The free wallpapers include Fireworks on New Year's, a collection of potentia
bucket list destinations, and a group of peaceful getaways. They're all available through the
Microsoft Store.

The Fireworks on New Year's set includes images of fireworks going off around the world. It
includes images from Tokyo, Montreal, Amsterdam, Singapore, and more. It's a festive way t
personalize your PC around this time of year.

 Buy one iPhone 11, get one for FREE at Verizon


Limited Time Offer

Several of the other collections that just became available are scenic and center around
destinations to visit or vacation ideas. The What Next PREMIUM collection has images of a
beach, a lakehouse, the plains, and more.

window 7 notebook
$0 Get latest price now
Alibaba.com

    

Source: Microsoft

Fireworks on New Year's


This wallpaper pack features 16 images of fireworks around the world, including photos from
Berlin, Tokyo, and Kuala Lumpur.

Free at Microsoft Store

We may earn a commission for purchases using our links. Learn more.

 News Windows 10

 View Comments (0)

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 22/23
1/3/2020 How to create and run a batch file on Windows 10

 

500M Consumers Reached Yearly

Copyright 2020 Mobile Nations • Terms and Conditions • Privacy Policy • Your Ad Choices • Careers • Licensing •
External Links Disclosure • Accessibility Statement

    

https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 23/23

Вам также может понравиться