How to Create a Batch File in Windows 10
Creating a batch file in Windows 10 is as simple as typing the commands you want to run into a blank notepad document, then saving the document as a .bat file instead of a text document. You can then run the file by clicking on it, which will automatically launch the Windows command shell and execute your commands. Here’s how to create a simple batch file in Windows 10:
Batch File Commands and Descriptions
A batch file is a special type of file that automatically opens a command window when activated. If you already know the commands that you need your file to execute, then you’re ready to go. Simply type the commands into Notepad in the manner outlined above, save as a .bat file, and open the batch file to execute the commands whenever you want. If you’re not sure what to put in your file, keep in mind that a batch file is essentially an ordered list of commands that will execute via the Windows command prompt. Anything you could type manually into the command prompt, you can put in a batch file. The file will then execute each command, in order, from the top to the bottom. Here are some useful commands to use in batch files, along with explanations of what they do:
@ECHO OFF: Disables display of the prompt. This is usually used at the beginning of a batch file for a cleaner display. You don’t need the @, but including it hides the ECHO OFF command as well. ECHO: Prints the following text to the command window. PAUSE: Causes the command window to remain open after the batch file is finished, or allows text in the window to be read before proceeding. TITLE: Places a custom title in the title bar of the command window. CLS: Clears the command window. EXIT: Exits and closes the command window. COPY: Copy one or more files. REM: Record comments or remarks. IPCONFIG: Display detailed IP information for each network adapter connected to your system. PING: Sends an Internet Control Message Protocol (ICMP) echo request to an IP address or website. TRACERT: Check your connection to an IP or website using ICMP. SET: Used to set variables. IF: Perform a conditional function based on user input or another variable.
Inserting Comments Into Batch Files
If you start a line in your batch file with two colons and a space, it won’t be executed. This allows you to easily insert comments into your batch file. Comments are useful to divide up a batch file into sections with a brief explanation as to the purpose of the section. Here’s an example of a batch file with comments: If you paste those commands into a batch file and run it, you’ll see an output like this: Comments aren’t necessary, but it is a useful option that you’ll tend to need more when creating complicated batch files with lots of sections. Here’s a slightly more complicated batch file that uses a variety of commands, comments, and actually performs a useful task: This file checks your internet connection using ipconfig and then pauses so you can examine it. It then pings google.com. Finally, it gives you the option to run the tracert command if you want. It then pauses a second time, allowing you to check the results before closing the window. The final result looks like this: