How to create a batch file in Windows

This is just a quick how-to for creating a batch (.bat) file in Windows.

Start by making sure you’re showing file extension for known file types. In Windows 7, you can open an explorer window and select Organize > Folder and Search Options.

Then go to the View tab and make sure ‘Hide extensions for known file types’ is unchecked.

Click OK, and now you can move on to creating a batch file.

Since a batch file is little more than a text file with a .bat extension, we need to create exactly that: A text file with the extension of .bat instead of .txt.

To create a batch file, just right-click and select New > Text Document

Once the text file is created, we need to change the extension. So just rename the file and change the extension to .bat instead of .txt. You’ll get the following pop-up, to which you simply say ‘Yes.’

Once the batch file is created, you have a new right-click context menu, as seeen below:

For this context menu, selecting Open runs the file, and selecting Edit opens the file in notepad for editing. You can also Run as administrator if your batch file contains commands that might require elevation.

That’s it!

One last thing. A Command (.cmd) file is esentially the same as a batch file, but with a few technical differences, and I deliberately didn’t address it here. If anyone wants to chime in the comments, please feel free.

Advertisements