How to Create and Run a Batch File in Windows 10 and 11 | Harper29
Call Us Free 773-759-7945
user heart cart0
order Free Shipping on Orders Over $100

How to Create and Run a Batch File in Windows 10 and 11

Batch files are the computer handyman's way of getting things done. They can automate everyday tasks, shorten the required time to do something, and translate a complex process into something anyone could operate.

In this article, you'll see how to write a simple batch file. You'll learn the basics of what batch files can do, and how to write them yourself. I'll also provide you with further resources for learning to write batch (BAT) files.

How to Create a Batch File on Windows

To create a Windows batch file, follow these steps:

  1. Open a text file, such as a Notepad or WordPad document.
  2. Add your commands, starting with @echo [off], followed by, each in a new line, title [title of your batch script], echo [first line], and pause.
  3. Save your file with the file extension BAT, for example, test.bat.
  4. To run your batch file, double-click the BAT file you just created.
  5. To edit your batch file, right-click the BAT file and select Edit.

Your raw file will look something like this:

And here's the corresponding command window for the example above:

If this was too quick, or if you want to learn more about BAT file commands and how to use them, read on!

Step 1: Create a BAT File

Let's say that you frequently have network issues; you constantly find yourself on the command prompt, typing in ipconfig, and pinging Google to troubleshoot network problems. After a while, you realize that it would be a bit more efficient if you just wrote a simple BAT file, stuck it on your USB stick, and used it on the machines you troubleshoot.

Create a New Text Document

A batch file simplifies repeatable computer tasks using the Windows command prompt. Below is an example of a batch file responsible for displaying some text in your command prompt. Create a new BAT file by right-clicking an empty space within a directory and selecting New, then Text Document.

Add Code

Double-click this New Text Document to open your default text editor. Copy and paste the following code into your text entry.

@echo off

title This is your first batch script!

echo Welcome to batch scripting!

pause

Save as BAT File

The above script echoes back the text "Welcome to batch scripting!" Save your file by heading to File > Save As, and then name your file what you'd like. End your file name with the added BAT extension, for example welcome.bat, and click OK. This will finalize the batch process. Now, double-click on your newly created batch file to activate it.

Don't assume that's all batch scripting can do. Batch scripts parameters are tweaked versions of command prompt codes, so you are only limited to what your command prompt can do. For those unfamiliar with the program, the command prompt is a powerful tool, but if you're using Windows 11, you should make the Windows Terminal your default app.

Step 2: Learn the Basics of Batch Scripting

Batch files use the same language as the command prompt. All you're doing is telling the command prompt what you want to input using a file, rather than typing it out in the command prompt. This saves you time and effort. It also allows you to put in some logic, like simple loops, conditional statements, etc. that procedural programming is capable of conceptually.

    • @echo: This parameter will allow you to view your working script in the command prompt. This parameter is useful for viewing your working code. If any issues arise from the batch file, you will be able to view the issues associated with your script using the echo function. Adding a following off to this parameter will allow you to quickly close your script after it has finished.
    • title: Providing much of the same function as a tag in HTML, this will provide a title for your batch script in your Command Prompt window.
    • cls: Clears your command prompt, best used when extraneous code can make what you're accessing had to find.
    • rem: Shorthand for remark provides the same functionality as

If you ever want to update your scheduled task, double-click the task to open the Properties window, which is where you can edit your triggers, actions, and more. In fact, you can add additional triggers and actions to the same scheduled task.

Automate the Simple Stuff With Batch Scripts

This is just a taste of what batch scripts have to offer. If you need something simple done over and over, whether it be ordering files, opening multiple web pages, renaming files en masse, or creating copies of important documents, you can make tedious tasks simple with batch scripts.

Leave a comment

Please note, comments must be approved before they are published