Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Create a Batch File on Windows 7/10/11

November 20, 2023
in Blog
0
ADVERTISEMENT

Table of Contents

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.

Bg2120

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 or create a new text file using Notepad or WordPad document or any text editor.

Bg2124

2️⃣ Add your commands:

  • @echo off : 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 This is your first batch script: Providing much of the same function as a <title> tag in HTML, this will provide a title for your batch script in your Command Prompt window.
  • echo Welcome to batch scripting: Print “Welcome to batch scripting” 
  • pause: Allows a break in the logical chain of your BAT file. This allows for users to read over command lines before proceeding with the code. The phrase “Press any key to continue…” will denote a pause.
@echo off
title This is your first batch script.
echo Welcome to batch scripting.
pause
Bg2121

3️⃣ Save your file with the file extension . Navigate to the File menu | Select Save As…

Bg2122

4️⃣ In the Save As window, change Save as type to All Files then type a filename with .bat as the file extension.

Bg2123

5️⃣ Now, double-click on your newly created batch file to run it. To edit the batch file, let’s right click on it then select Edit.

Bg2125

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

Bg2126

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.

More basic parameters for batch scripting:

  • 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 <!– tag in HTML. Rem statements are not entered into your code. Instead, they are used to explain and give information regarding the code.
  • %%a: Each file in the folder.
  • (“.\”): The root folder. When using the command prompt, one must direct the prompt to a particular directory before changing a files name, deleting a file, and so on. With batch files, you only need to paste your BAT file into the directory of your choosing.

The library for batch variables is huge, to say the least. Luckily there is a Wikibook entry that holds the extensive library of batch script parameters and variables at your disposal.

Examples of batch scripts

We’ll create examples of batch scripts which can simplify your daily online and offline activities.

Batch file to open websites

The below script stacks one start “” parameter on top of the other to open some websites using a batch file on multiple tabs. You can replace the links provided with ones of your choosing.

Without the pause parameter, the batch file will close automatically after executing the last command.

@echo off
start "" http://www.bbc.com
start "" https://google.com/
start "" https://bonguides.com/
Bg2127

Batch file that opens multiple programs

If you find yourself opening the same set of apps over and over again, you can now create a custom launcher batch file that opens multiple programs with a single click.

All you need to find out is the file location. Let’s say you need to do some work, and you want to open Excel, the Calculator, and Microsoft Edge. Here’s the code for that:

@echo off
cd "C:\Program Files\Microsoft Office\root\Office16\"
start excel.exe

start calc.exe

cd "C:\Program Files (x86)\Microsoft\Edge\Application"
start msedge.exe
Bg2128

Batch file to restart your computer

The below script will restart your computer after 5 seconds.

@echo off
shutdown -r -t 5
Bg2129

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 in masse, or creating copies of important documents, you can make tedious tasks simple with batch scripts.

5/5 - (1 vote)
Previous Post

How to Install Microsoft Office Using Office Deployment Tool ODT

Next Post

How to Open Multiple URLs in a Browser Using a Batch File

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory