How to Create a Batch File in Windows 10 | Automate Daily Tasks Easily

In this guide, I’ll share how to create a batch file in Windows 10 and the related benefits.

Batch File is quite a common word for most Windows users. Flashback to good old days with MS-DOS, even opening a simple folder required a user to enter a few commands first. Now, you just have to hover the mouse over the icon, double click and voila! Your folder will open. It’s that easy.

However, there are still a few tasks that require CMD prompt.

Think about it!

Maybe you have frequent networking issues. Just create a batch file for ping command and you’re good to use it whenever your internet starts acting up.

Perhaps you wish to automate other tasks on Windows 10. Say, shutting down an application or your PC after a certain interval. Create your batch file with the commands and double click it.

The commands will automatically execute the task for you.

Now, there’s too much of Batch File discussion here.

For beginners who are wondering what exactly it is, just read on for a quick answer.

What is a Batch File?

A batch file contains a series of commands that are executed when you double click it much like any other file on Windows 10. The batch file saves your time by automating certain tasks for you that would otherwise require typing same commands on Command Prompt over and over again.

Of course, there’s more reasons to use a batch file.

If you’re uncomfortable with using Command Prompt, a batch file is just the solution for you. This simple alternative can act as a mediator between Windows and Command prompt for you.

Now, it’s time to learn a few commands to get you started.

Basic Commands You Must Know First

Creating a batch file is all about commands. If you know how to write commands, great!

You can skip this portion.

But for beginners, these few commands will help to just get you started with the tutorial ahead.

Let’s begin with the learning:

1. Title

This command is used to replace the default title on top on the command prompt window.

2. Echo

Echo command is used to display the content on the terminal. You can set this command to ON or OFF by writing ECHO ON or ECHO OFF.

As a general rule, echo off is used at the start of each batch file to hide the commands used for the task.

For displaying anything on the terminal, use the command echo followed by the string you wish to print.

Eg, echo this is freaksense.

Now, This is freaksense will be displayed on the terminal.

3. Pause

This CMD command is used to pause or add a break to the series of commands in a batch file. It is presented by the phrase “Press any Key to continue. . .”

4. :: or REM

Shorthand for Remark, you can use this command to enter a comment or remark for your commands. As an explanation, this command may be used.

5. Cls

This command is used to clear the command prompt screen.

6. Exit

Use this command when you wish to exit the CMD on Windows 10.

Now, these commands are enough to get you started for creating a basic batch file.

Here’s a complete reference guide of all Windows CMD commands if you wish to learn more about it.

Now its time to create a batch file on Windows 10

In this tutorial, I’ll be creating a batch file to display “Welcome to Freaksense” on the command prompt.

  1. Open Notepad
    how to create a batch file in windows 10

  3. Enter the following commands
echo off 
Title Freaksense tutorial
:: This statement is a comment
Echo Welcome to freaksense
Echo I hope you found this tutorial useful
Echo Goodbye

Code Explanation

The first line echo off is used to turn the display off for all the commands.

In the second line, title freaksense tutorial will display Freaksense tutorial on top of the CMD screen.

The next line is a comment or a general remark.

In the next line, I’ve used echo command to display the string.

Pause command will ask you to press a key to continue.

Next two lines will display the strings.

The last command will exit once you press any key. Alternately, you can use the exit command. It’ll exit without any key event instantly.

Note: All the commands have to be entered on a new line.

How to Save a Batch File in Windows 10

A batch file has the extension .bat

For saving a batch file in notepad,

  1. Click File> Save As.
    how to create a batch file in windows 10

  3. A new Window will appear. Just enter the name you wish and change the default extension from .txt to .bat.
    how to create a batch file in windows 10

  5. Select Save As Type to All Files.
  6. This is it. Click on Save and you’re done.

How to Run a Batch File in Windows 10

Go to the folder where you have saved your batch file.

Just double click on the file name.
how to create a batch file in windows 10

And there you go…

Your CMD commands will be executed instantly.
how to create a batch file in windows 10

After you press any key…
how to create a batch file in windows 10

Press any key again and cmd will exit.

That was all for this code!

Give yourself a pat on the back. You’ve created your first batch file.

This is just a teensy bit of the work a batch file can do for you. Learn a few more commands and get started with creating your batch files for automation of tasks like putting a computer to sleep after a certain time, backup your system or checking the network connection.

If you’d like us to write more about batch files or something else, feel free to do so. Just drop a comment below and we may write another topic based on your suggestions.

Related Articles