How to Create a Batch File to Run Command in Windows

What is a batch file? The name of batch file is not known to most people, even for long-time Windows users. However, when it comes to CMD, or Command Prompt, many people would show knowing smiles and nodding heads, or at least heard that its functions for fixing SD card not detected or format not complete successfully issues.

In brief, a batch file is a finish package that contains a lot of command lines. When people run a batch file, the commands written in it are executed in Command Prompt automatically. In this article, we are going to introduce batch files and how to create a batch file to run command in Windows 10/8/7.

Create a Batch File to Run Command in Windows

Part 1. What Exactly Is A Batch File?

The batch file is a file that has extensions like. btm, .cmd, .bat and contains all the command line prompts that have been pre-typed in. If you try to double click on a batch file in order to run it, then the commands that are present inside the file will be run in serial order.

Witch batch files, people don’t have to enter commands manually and repeatedly, which is a really tedious job, so the set of commands is also known as a batch script. These scripts can be transferred or shared so as to help people save time and present works decently.

Pro tips: Batch files are useful media for saving accredited and valuable works and innovations. To void the loss of production, everyone should keep important data safe. In case of accidents which cause data loss, make sure to use iReparo Data Recovery for PC to get them back.

Download iReparo for PC Windows Download iReparo for PC Mac

Are you curious about how to make a batch file in your windows 10 PC now? Keep reading to know more.

Part 2. Batch File Commands You Need to Know

Before starting your first batch file, you should know some of the basic commands that will help you in the creation of batch files. Some of the commands are:

Part 3. How to Create A Batch File in Windows 10 Computer

Now we are going to demonstrate how to create a simple batch file in Windows 10. The steps are be similar in Windows 7 and 8, so make sure to check them out carefully.

Notepad is usually one of the most favoured tools, but Text Document the system utility is also good to go.

How to Create A Batch File in Windows

This is a simple batch file, which doesn’t have meaningful information or function, but it is good sample of how a batch file looks like. Actually, all great batch files are written like this one and have benefited countless of people.

Part 4. How to Run a Batch File in Windows

Whether the batch file is named with .bat, .btm or .cmd, the easiest way to run a batch file is by double-cling on it. For example, if you run the batch file created just now, it should look like:

How to Run a Batch File in Windows

You can explore more fun from batch files by modifying the existing BAT file or practice with the following practical examples.

Example 1. Create a batch to generate Energy Report:

Create a new text file, then type the following commands:
Save the file with an extension of .bat, instead of the default .txt. Make sure to use the correct file extension.

Example 2. Create a batch file to generate Battery Report:

Create a new text file, then type the following commands:
powercfg /batteryreport
Save the file with .bat extension.

Important: The Battery Report and Energy Report batch files only work with administrator privileges. So, you will have to run these batch files with “Run as Administrator” option from right-click menu.

Bottom Line

In this tutorial, we have learnt how to easily create and run batch files. Now you can save a lot of time by utilizing other people’s works in batch files, or build batch files with helpful commands in it and benefit others. Actually, there are many more tips and tricks about Windows CMD available for you.

Try this out and enjoy the fun in it, and remember to share your experience with us.

/ Public by Jihosoft

Follow Jihosoft