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
01
Create a working folder, for example C:\Scripts\MyTask.
02
Open Notepad.
03
Paste your Command Prompt commands into Notepad.
04
Click File → Save As.
05
Set Save as type to All Files.
06
Save the file with a .bat extension, for example run-task.bat.
07
Open Command Prompt in the script folder.
08
Run the batch file and verify the result.
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.
Copy
@echo offcd /d "%~dp0"echo Task startedREM Add your commands below this lineexit /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.
Copy
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.