banner



How To Create A Simple Bat File

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:

  • Title – This command will help you to display the title of the text that is displayed right on top of the command prompt window.
  • Echo – The function of echo is to display the strings that you give as the input as the output. It is optional to use ON or OFF to define your commands. If you turn the echo on, then the command prompt will display the command that it is currently executing.
  • Pause – This one is used to stop any execution of batch files. So, this means that the command is over and now the execution needs to stop.
  • Exit – The exit command, of course, is used for exiting the command prompt window. When this line is executed, you will see the screen automatically closed.
  • Cls – As you might have guessed by now, cls is used for clearing the screen of command prompt. So, anything that you wrote previously will all get erased from the screen, and you get a completely blank space to type in all the commands.
  • :: – This one is used for adding any kind of comment on the batch file that you are creating. Addition of comments increases the readability of the files and makes it easier for the readers to understand the function of the commands.

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.

  • Firstly, create a new file by right click > New > Text Document, then assign a random name to it with .bat as the extension.
  • Right-click the BAT file and choose Edit, enter the following command lines, then save and close the file.
    echo off
    title This is a Test Batch File
    :: See the title at the top.
    echo Test file executed.
    echo I want to learn how to create batch files.
    Pause

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:
powercfg/energy
C:\WINDOWS\system32\energy-report.html
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
C:\Windows\System32\battery-report.html
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.

How To Create A Simple Bat File

Source: https://www.jiho.com/en/tips/create-batch-file-to-run-command-windows.html

Posted by: englesdoony1936.blogspot.com

0 Response to "How To Create A Simple Bat File"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel