Windows scripting reference
How to Create a Batch Script
This guide shows how to create, save, edit, and run a Windows batch script.
You can use batch scripts for simple automation, software deployment wrappers, troubleshooting commands, or repeatable Command Prompt tasks.
What is a batch script?
A batch script is a plain text file that runs Command Prompt commands in order. It uses the .bat file extension. Batch scripts are useful when you want to repeat the same commands without typing them manually each time.
| File extension | .bat |
|---|---|
| Default shell | Command Prompt |
| Best for | Simple command wrappers, software install commands, file operations, and repeatable admin tasks. |
| Skill level | Beginner friendly when commands are copied carefully and tested first. |
Step-by-step: create a batch script
Use these steps to create a batch script from scratch.
Create the script file
C:\Scripts\MyTask..bat extension, for example run-task.bat.Basic batch script template
This template shows a safe structure for a simple batch file: hide repeated command output, use the script folder as the working folder, run commands, and return the last exit code.
@echo off
cd /d "%~dp0"
echo Task started
REM Add your commands below this line
exit /b %errorlevel%
How to run a batch script
Open Command Prompt, move to the folder that contains the batch file, then run it by typing the file name.
cd /d "C:\Scripts\MyTask"
run-task.bat
Useful examples
| Print a message | echo Hello |
|---|---|
| Change folder | cd /d "C:\Scripts" |
| Run an installer | setup.exe /quiet |
| Return an exit code | exit /b %errorlevel% |
Beginner checklist
| Correct extension | The file ends with .bat, not .txt. |
|---|---|
| Plain text | The script was saved from Notepad or another plain text editor. |
| Working folder | The script is run from the folder where related files are stored. |
| Permissions | Admin tasks are tested from an elevated Command Prompt. |
| Testing | The script is tested on a safe machine before production use. |


