What is a .BAT file? How to create and use BAT files on Windows computers
With the convenience of pre-installed software on the computer , using the BAT file on Windows is also one of the useful tools. In this article, I will share some knowledge about BAT files and instructions for creating and using BAT files on Windows computers. Let's see it now!
1. What is a .BAT file?
Define
File BAT or Executable Files - DOS Batch File is a file in Text format developed by Microsoft. The BAT file executes tasks on the computer automatically and is a DOS executable file used to execute commands with the Windows Command Prompt (cmd.exe).
A BAT file consists of a series of commands, lines in plain text that are executed to perform various tasks, such as starting programs or running maintenance utilities in Windows.
History
The BAT file was introduced with the MS-DOS operating system with the ability to execute multiple commands in batch instead of running each command as before.
BAT files are still used today on Microsoft Windows operating systems , with many improvements such as the ability to perform calculations, read data from the keyboard or change the color of the Command Prompt window.
The BAT file was born with the purpose of making work on the computer more efficient such as reducing network problems, avoiding frequent opening of the Command Prompt dialog box to enter commands like ipconfig /release, /renew or need to delete files temporary %temp%… , especially the user can use this file for all other computers if desired.
For example
- Currently, there are many applications of BAT files depending on the needs and creativity of each administrator.
- There are many Batch Files written based on Wmic .
- To write Hello World program, we can use the following simple example:
@echo off
cls
title Hello World
cls
color 02
cls
echo Hello world!
Inside:
- @: Make the command not display on the screen.
- echo off: Switch the mode to hide the command (ie "@" will be added before the statements).
- cls: The command to clear the screen.
- title Hello World: This is the command used to display the name of the Command Prompt window. In this case, the window is named Hello World.
- color 02: Is the command to change the font color to increase the beauty of the program. The first letter specifies the background color (0), the second indicates the font color (2).
- echo Hello world: Is the command written on the screen. In this example, we write on the screen the words Hello world.
Note: echo off and echo on cannot be written to the screen and echo can be used. to go down the line.
2. Some keywords in Batch
Batch is a programming language that is based on batch executable files (BAT files) to run. So this language also has certain keywords:
- ver: Returns the version of MS-DOS in use.
- cd: Redirects the working directory.
- cls: Clear the MS-DOS screen.
- copy: Copy files.
- del: Delete files.
- dir: Displays the contents of a directory.
- echo: Display text on the MS-DOS screen.
- exit: Exit the program.
- md: Create a new directory where the current working location is located.
- pause: Prevents the program from exiting and waits until any key on the keyboard is pressed.
3. How to create and use BAT files on Windows computers
The BAT file has a lot of functions, and if used incorrectly on Windows, it can erase everything from the data, the hard drive or damage the operating system itself.
To create and use a BAT file on a Windows computer, you can follow these steps:
Step 1: Create file BAT
Open the folder where you want to save the BAT file > Right-click any empty space > Select New > Select Text Document.
Step 2: Enter the command
Enter any content, command for the file > Click File > Select Save As.
The BAT file has 7 basic commands:
- TITLE: The window name for the BAT file.
- ECHO: Print command of the BAT file.
- ECHO OFF: The command is placed at the top of the BAT file. When running this command, the commands below ECHO OFF will not be displayed.
- PAUSE: When using this command, a message 'Press any key to continue…' will be displayed on the screen, all commands in the BAT file will be paused until you press any key to restart.
- CLS: Clean the DOS window screen.
- IPCONFIG: Network information displayed on DOS.
- PING: Ping to the IP address, indicating whether or not you can contact the computer. This command also returns the delay (ping time) and will ping 3 times by default.
Step 3: Proceed to save the file
In the File name section, name the file with the structure *.bat > In the Save as Type section, select All Files > Select Save.
Finally, you will see your BAT file has a gear shape, the BAT file creation is complete.
4. Other applications when using BAT . files
In addition to the very basic ways to use the BAT file on Windwos, the BAT file has many other uses and features such as:
- Creating BAT files to delete files and folders on the computer is a feature that the file can completely do if the user has ever used the Command Prompt, knows how to use it via Command Prompt.
- File BAT can fix Full Disk error, an extremely annoying error for users.
- Set folder password in computer with BAT file. This is an advanced trick with many complex commands, users do not need to know too much about the code can also use this way.
- Using BAT files is a really useful solution to run programs (such as Java) with just one command line, saving time instead of having to type commands from scratch.
- After understanding the operation and commands of the BAT file, users can easily create their own files for their own work quickly.
Note: Some commands are available for BAT files, you can see HERE. you can write your own programs or refer to the examples available HERE.
5. Difference between BAT and CMD . files
- Same:
+ BAT file and CMD file are both a collection of Command Line execution commands to perform one or several certain tasks.
+ The way to create and use these two file types is similar.
- Different:
Characteristics | BAT file | CMD . file |
When an error occurs | If there is an error line in the BAT file, it will ignore that error line to execute the next instructions without affecting anything. | If there is an error in the CMD file, it will be considered as an error (not executable). |
Prioritization and implementation support | In Windows NT, the BAT file is more commonly used. | In Windows NT, CMD files are not preferred to BAT files. |
Utilities | - Use the BAT file in the CD/USB to automatically run and install the application. - Use the BAT file to configure the computer extremely fast, specifically: + Change the amount of virtual RAM with Command Line. + Change computer password using Command Line. + Restart the computer (reset) or shut down the computer (shutdown) using the Command Line. + Uninstall (uninstall) Windows Update using Command Line. + Open an application or a website using the Command Line. | - Usually used to store a series of executable commands. - Can be converted to another format to suit the intended use. - Used a lot on Windows versions. |
Hopefully, after reading this article, you have knowledge about BAT files and how to create and use BAT files on Windows computers. Thank you for reading the article, see you in the next post!
You should read it
- What is ISO file?
- How to create an EXE installation file
- Instructions for creating and using BAT file on Windows
- Difference between EXE file and MSI file
- What is DMG file?
- How to open and read the .DAT file?
- What is an XML file and how to open it?
- The Fsutil file in Windows
- What is a DLL file, and how does this file work?
- What file is PAT? How to open, edit and convert PAT files
- What is a .tmp file? How to open .tmp file on Windows computer?
- What are UDF files?
Maybe you are interested
10 Windows 11 settings to maximize laptop battery life
Compare iPhone 16 battery life with other iPhones
How to charge phone with battery
List of Samsung smartphones with the longest battery life
American company develops nuclear batteries that operate continuously for 50 years
Compare the battery life of current flagship models