With the convenience of pre-installed software on modern Windows systems, many useful and unique tools are often overlooked. Using BAT files on Windows is one of those tools. In reality, using BAT files on Windows is mostly reserved for those who are passionate and curious about computers, rather than using them for everyday tasks. Furthermore, using BAT files on Windows is not simple because it involves running pre-programmed commands, something that few people can learn and do.
Talking about .BAT files, we can apply them to many things on a computer that you may not be aware of, such as creating a .BAT file to shut down the computer. There are many ways to shut down a computer, such as using the Run tool, Command Prompt, and creating a .BAT file to shut down the computer is a feature that users can easily accomplish.
How to Create and Utilize BAT Files on Windows Computers
What is a BAT File?
BAT File or more formally known as Batch is a programming language based on batch execution files (*.bat, *.cmd,...) for running commands. They are executed in a cmd - Command Prompt window to execute command lines. Batch files have various functionalities, and if not used correctly on Windows, they can delete data, corrupt the hard drive, or damage the operating system.
How to Create a BAT File on Windows
Step 1: To create a BAT file, simply right-click on any empty space, then choose New > Text Document.
Step 2: Here, you input the content, any command for the file, just make sure it has text, then click on File > choose Save As.
Step 3: In the File name section, name the file, as long as the last character is .BAT, and in the Save as Type
If there is a warning about the font format, simply ignore it and press OK.
Finally, you'll see your BAT file with a gear icon, the process of creating a BAT file is complete.
Basic Command Usage for BAT Files
In reality, BAT files have numerous commands, and mastering the use of BAT files on Windows is not a simple task. However, for those new to using BAT files on Windows, you can take a look at the following commands to get a brief idea of how to use BAT files.
- Title: Window title for the BAT file.
- Echo: A command in BAT files; any information following echo will be displayed in the Command Prompt.
- Echo off: Placed at the beginning of a BAT file, commands below this line will not be executed.
- Pause: Used to temporarily halt BAT file commands until restarted.
- cls: Clears all text displayed on the screen when you've entered too many operations. This command is similar to Clear in the Command Prompt.
- ipconfig: Checks the IP address and related parameters.
- ping: Pings the IP address, indicating whether it responds quickly or slowly. For example, ping Mytour.
- shutdown: Command used to turn off the computer, for instance, shutdown -s -t 500 (will shut down the computer in 500 seconds).
Write Content and Use BAT Files on Windows
Step 1: We can create a BAT file as mentioned above and write the content directly. In case you already have a BAT file, just right-click and choose Edit to proceed with editing and writing content for the BAT file.
Step 2: Here, try writing a command, for example, ping a web address that Mytour has mentioned above. For instance, if we want to ping the Mytour address, we would write the command as follows:
ping www.Mytour -t
With Ping being a command used to check the response of a website.
-t represents time; when adding -t, the system will automatically ping indefinitely until you turn it off.
Step 3: Afterward, you select File > Save to save this BAT file.
Step 4: Double-click on that BAT file to run it; you will see the system automatically running the ping command you provided above.
Step 5: Another example is using the shutdown command to turn off the computer, a familiar command on computers that helps you schedule a shutdown. Similarly, you enter the command as follows:
Shutdown -s -t 500
Using shutdown is a command to turn off the computer.
-s is the command to shut down the computer, where s stands for shutdown.
-t is the time, with 500 calculated in seconds (500 seconds).
Immediately, the system will display a notification that the computer will be shut down in 500 seconds (8 minutes).
Other Applications when using BAT Files on Windows
Above are just some very basic uses of BAT files on Windows to help you understand more about this tool. There are many other functions and features of BAT files that you may not be aware of.
- For example, we can create a BAT file to delete files or folders on the computer. This is a feature that the file can completely accomplish if you have ever used Command Prompt, know how to use it through Command Prompt, then you can understand how to do it. Refer to the article on creating a BAT file to delete files on the computer and practice it; this is a fairly simple article for readers to get acquainted with BAT files.
- Alternatively, create a BAT file to fix the Full Disk error, a very annoying issue for users. However, if you apply creating a BAT file to fix Full Disk error, this becomes entirely simple.
- Another advanced trick using BAT files is setting a password for a folder on the computer. This is a sophisticated trick with many complex commands; you don't need to know too much about code to use this. Just copy the reference code in the article setting a password for a computer folder and apply it to your file.
Through this Mytour article, we hope you have gained some understanding of BAT files and how to use BAT files on Windows as mentioned in the article. If you explore more about BAT files, you will find many things you can do with BAT files.
Aside from BAT files, Command Prompt (CMD) is also a tool pre-installed on Windows but often overlooked. However, if you become proficient or know how to use Command Prompt a bit, you will find this tool extremely useful. Refer to common CMD commands in computers that you should know here to learn more about Command Prompt or Powershell on Windows 10.