Windows 11 · Windows
Create and Run a Batch File in Windows 11
Source-checked About 10 minutes
Answer
Write trusted Windows commands in a plain-text file, save it with a.bat extension, and run it with only the permissions those commands require. Read every command before executing a batch file.
Choose documented commands
Plan a short sequence using commands you understand and verify each one in Microsoft's Windows command reference. Never paste an unknown script into a batch file.
Write the commands in Notepad
Open Notepad and enter one command per line. Put paths containing spaces in quotation marks and use REM at the start of a comment line.
Save the .bat file
Choose File > Save As, set Save as type to All files, and use a clear filename ending in .bat, such as backup-documents.bat.
Confirm the extension
In File Explorer, enable View > Show > File name extensions and confirm the file ends in .bat, not .bat.txt.
Run with minimum privilege
Double-click it for ordinary user commands. Use Run as administrator only when a command you reviewed explicitly requires elevation.
Test harmlessly before relying on it
Run the file against a temporary test folder or with read-only commands first. Check every variable and destination, especially before using DEL, MOVE, ROBOCOPY, shutdown, service, registry, or disk commands that can change or remove data.
Verify the output
Check the console and the files or settings the script was meant to change. Add pause temporarily if the window closes before you can read an error.
Video walkthrough
If it does not work
- If Windows opens the file in Notepad, correct a hidden .txt extension and save it again as All files.
- If a path cannot be found, quote the full path and account for the batch file's working directory.
Sources and verification
Checked against official documentation on . Scope: Windows.
Follow the linked first-party guidance if labels differ after a platform or app update.
