Introduction to Windows Batch Scripting

Nitish Kumar Singh

Jun 2, 2025

Learn about batch script in Windows that is used for automating tasks, running scripts and programs, doing file operations, and much more.

Photo by kabir cheema on Unsplash

Windows Batch Script, also known as DOS commands, is a scripting language used to automate tasks in Windows using .bat files. In this post, we will explore how batch scripts work and how to create them.

What is Batch Script?

Batch Script is a scripting language used in Windows to automate command-line tasks by writing a sequence of commands in a .bat (batch) file. These commands are interpreted and executed line by line by the Windows Command Prompt (cmd.exe).

Batch Script is a plain text script containing a series of DOS or CMD commands that execute automatically when the file is run, and to run the file we just need to double-click on it.

A simple batch script to greet the user:

@echo off
echo Hello, Nitish!
pause

What does this code mean? @echo off means hide execution command logs, echo Hello, Nitish! prints the greeting message, and pause is used to pause until any key is pressed.

Is Batch Script Like a Language?

Yes, batch script is a scripting language, but not a full programming language. It's used to automate tasks by writing commands that are executed by the Windows Command Prompt (cmd.exe).

We can do basic operations of a programming language like create variables, write conditions, and run loops in Windows batch script.

Where Do We Use Batch Script?

We use batch scripts primarily on Windows systems or servers to automate tasks through the Command Prompt (cmd.exe). Below are the most common real-world use cases:

  • Automating System Tasks: We can use it to delete temporary files, clean up old folders, create or rename files in bulk, and back up data from one location to another.
  • Software Installation Scripts: We can use it to automate the installation of multiple programs at once, where a program works with the help of multiple tools.
  • Scheduled Tasks: Run scripts automatically at a specific time using Task Scheduler in Windows.

Examples of Batch Script Usage

Now let's see some of the use cases where batch scripts make tasks easier and faster.

1. The below code copies all files from a project folder to a backup drive.

@echo off
xcopy "C:\MyProject" "D:\MyBackup" /s /e /y
echo Backup completed!

xcopy copies all subfolders and files. The /s /e flags ensure even empty folders are included, and /y skips confirmation.

2. With the following code, we can launch Notepad and Calculator together with one click.

@echo off
start notepad
start calc

3. We can start our Node.js Express server and open the default browser at the server URL (e.g., http://localhost:3000).

@echo off
cd /d "C:\Path\To\Our\ExpressApp"
start cmd /k "npm start"
timeout /t 3 > nul
start http://localhost:3000

This script starts our Express server using npm start and, after a short wait, opens the app in our default browser at http://localhost:3000. It helps us launch both the server and browser with a single double-click on a desktop shortcut.

Now we have successfully explored the basics of Windows Batch Scripts, including what they are, where they’re used, and how to write and run them. Batch scripting is a simple yet powerful tool for automating tasks on Windows.

I hope you enjoyed learning about batch scripts with me, understood the logic behind each use case, and found the examples helpful in building your scripting and automation skills.

Thanks for reading! 🤝 Happy Coding! ✨

Published on Jun 2, 2025
Comments (undefined)

Read More