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
- 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
May be interested
- How to create ISO file with WinRARhow to create iso file with winrar. winrar only supports viewing and extracting iso files. iso files created with winrar can only be viewed and extracted by winrar software. if you create the iso file of the boot disk, windows will have file corrupt error and we should create the iso file with specialized software such as poweriso, ultraiso ...
- How to create ZIP files on Androidthe zip file format allows you to compress large files and folders into a smaller file. you can then extract these files whenever you need to use them. creating zip files is easy, and you can do it on any device you have - including android phones.
- What is DMG file?the main reason that macos uses dmg files is to make sure the file is properly downloaded and not spoofed. dmg files undergo a 'checksum' to verify that the file is 100% intact.
- Instructions for creating a PDF file from multiple image files on Windowspdfs are designed to support raw text with fonts, images, sound and many other effects. if you have a collection of photos and text documents that you want to scan to your computer in jpegs format, you can combine these files into one pdf file for easy sharing.
- How to Copy Secure PDF Files on Windows or Mac Computersthis is an article showing how to copy text from a pdf file with editing functions locked on a windows or mac computer. when a pdf file has a password set to lock the editing function, you cannot copy the content in most pdf file viewing programs. if you don't know the password, you can save the file as an unsecured pdf using google chrome or unlock it using the smallpdf site. if you know the password, unlock the file using adobe acrobat pro. these methods only work if you can still view and print the pdf without a password. if the pdf file is encrypted and has a password lock that prevents you from viewing the file the first time you open it, it means you can't bypass the security settings.if you need to create, merge, or convert pdf files, try tipsmake's pdf toolkit - it's a free and easy-to-use tool that helps you process documents more efficiently.
- How to create and extract RAR files in Windows 10rar files are one of the most common and used file types on pc. their usage has not changed in windows 10. in this article, tipsmake.com will talk about rar files, as well as how to create and extract them in windows 10.
- How to Launch BAT Files on Windowstipsmake today will show you how to launch bat files (also known as batch files) on windows computers. batch files are used for many purposes, such as automating frequently used tasks. you can launch the file in file explorer as usual, or execute it from the command line in the command prompt.
- Create ZIP files in just two steps in Mac OS Xyou have a lot of image files you want to share with your friends, but are you afraid of the size? need to create a zip file to compress the photos together on mac os x without using the software?
- How to Create a Computer Filethis wikihow teaches you how to create a new file, such as a document, on your computer. windows users can create basic files from within file explorer, but all computer users can create a new file from within the 'file' or 'new' menu in...
- How to tag files on Windows 10 with Taggrthe taggr application will tag any file to search and open faster.