How to Create a Batch File in Windows

Windows batch file creation illustration

A batch file is a plain text file saved with a .bat extension. It runs Command Prompt commands in order, which makes it useful for repetitive tasks like opening folders, copying files, or launching apps together.

These steps apply to Windows 10 and Windows 11 and require no extra software.

Does This Affect You?

Batch files are best for simple, repeatable command-line tasks. They are powerful enough to delete or move files, so read any batch file before running it.

Create Your First Batch File

  1. Open Notepad.
  2. Type commands, one per line.
  3. Use File > Save As.
  4. Set Save as type to All Files.
  5. Name the file with a .bat extension, such as open-documents.bat.
  6. Save it somewhere easy to find and double-click it to run.
@echo off
echo Opening Documents folder...
start "" "C:UsersYourNameDocuments"
echo Done!
pause

@echo off keeps the output clean, echo prints text, start opens a file, folder, or program, and pause keeps the window open so you can read the result.

Run a Batch File at Startup

  1. Press Windows key + R.
  2. Type shell:startup and press Enter.
  3. Copy the batch file or a shortcut to it into that Startup folder.
  4. Sign out and back in, or restart, to test it.
  5. Remove the file or shortcut from the same folder to stop it running at startup.

Batch File Tips

Useful Commands

cd changes folders, copy and xcopy copy files, robocopy is better for larger copy jobs, mkdir creates folders, and del deletes files. Be careful with delete commands because scripts can run quickly.

Run as Administrator

Right-click the batch file and choose Run as administrator when a command needs elevated rights.

Add Comments

Use REM or :: at the start of a line to leave notes that do not run as commands.

Be Careful with Downloaded Batch Files

Open downloaded batch files in Notepad before running them. Only run scripts from sources you trust.

Sources

  • Microsoft Learn: Batch files
  • Microsoft Learn: Command-line reference A-Z
  • Microsoft Support: Add an app to run automatically at startup
Disclosure: This post may contain affiliate links which means I may receive a commission for purchases made through links. I will only recommend products that I have personally used! Learn more on my Private Policy page.
A thoughtful woman reads a newspaper while enjoying coffee at an indoor workspace.

DEALWEEK

SUBSCRIBE AND GET 20% OFF YOUR NEXT ORDER! OFFER ENDS SOON - DON’T MISS OUT!

We don’t spam! Read our privacy policy for more info.

Shopping Cart