Last updated on November 10th, 2026 at 10:23 am
Open Notepad, type the commands you want Windows 10 to run, one per line, then select File > Save As. Set Save as type to All Files (*.*) and give the file a name ending in .bat, such as open-contoso.bat. Double-click it and Windows runs the commands in order. With folder names already in a spreadsheet, you can create folders from an Excel list using a batch file like this.
1. Write the commands in Notepad
- Select Start, type Notepad, and open it.
- Type your commands. This example opens a folder and waits for a key press:

What each line does:
@echo offstops the commands themselves from showing, so only the messages appear.remadds a note that Windows ignores.echoshows a message.start "" "C:\Users\Alex\Documents\Contoso"opens the folder. Change the path to one of your own.pausewaits for you to press a key before the window closes.
Why does the window close right away?
The batch file finished. Add pause as the last line to keep the window open.
How do I run a batch file when Windows starts?
Press Windows logo key + R, type shell:startup, and press Enter. Put a shortcut to the batch file in the folder that opens. It runs each time you sign in.
2. Save it as a .bat file
- Select File > Save As.
- In File name, type a name ending in .bat, for example open-contoso.bat.
- Set Save as type to All Files (*.*). If you skip this, Notepad saves it as a .txt file.
- Select Save.

To check the extension, turn on file name extensions in File Explorer.
3. Run or edit the batch file
- Run it: double-click the file.
- Run it as administrator: right-click it and select Run as administrator. Only do this for commands that need it.
- Edit it: right-click the file and select Edit. It opens in Notepad.
- Run it on a schedule: use Task Scheduler to start it at a set time.
Handy commands for batch files
- start opens a program, file, or website, such as start notepad.
- cd /d “%~dp0” switches to the folder the batch file is in, so the rest of the commands work from there.
Add comments, questions and variables
Once the basics work, a few extras make a batch file more useful. This one asks for a name and creates a folder with it on your desktop: One practical use is a pair of tiny files that switch the Java version for the current window with two set commands.
@echo off
REM Ask for a folder name, then create it on the desktop
set /p name=Folder name:
mkdir "%USERPROFILE%\Desktop\%name%"
echo Created %name% on your desktop.
pause
- REM or :: at the start of a line marks a comment that Windows skips.
- set /p asks a question and stores the answer. Use it later by wrapping the name in percent signs, like %name%.
- %1 holds whatever you pass to the file. If you drag a file onto the .bat icon, %1 is that file’s full path.
- %USERPROFILE% and other built-in variables point to your own folders, so the same file works for any user.
Can I make a batch file run without showing a window?
Not with a .bat file alone. Task Scheduler can run it in the background if you choose Run whether user is logged on or not.
The official command pages for echo, rem, and pause list every option.
Need a plain text settings file instead of a script? You can create an INI file in Windows 10. Related: creating a macro in Windows 10.
Stay safe with batch files
- Only run batch files you wrote yourself or that come from someone you trust. A batch file can delete files or change settings.
- Test new commands first in a Command Prompt window.
If the batch file doesn’t work
- It opens in Notepad instead of running. It was saved as a .txt file, such as open-contoso.bat.txt. Turn on file name extensions and rename it so it ends in .bat only.
- “Is not recognized as an internal or external command.” Check the spelling, and use the full path to the program if it isn’t in a standard folder.
- A path with spaces fails. Put quotes around it, such as “C:\Users\Sam\My Files”.
- It works normally but not as administrator. Run as administrator starts in the Windows System32 folder. Add cd /d “%~dp0” near the top so it starts in its own folder.

Matt Jacobs writes and maintains the guides on Support Your Tech, which he started in 2017. He spent most of his career keeping small-business PCs running and still takes the occasional consulting job, so the steps here come from fixing the same problems on other people’s computers. Every guide is checked on his own Windows 11, Windows 10, Mac, iPhone and iPad before it goes up.