What is a .BAT file? How to create and use BAT files on Windows computers

The article provides information about BAT files, history, examples, how to create and use BAT files on Windows computers, other applications when using BAT files and the difference between BAT and CMD files. Click to view now!

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).

Picture 1 of What is a .BAT file? How to create and use BAT files on Windows computers

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:

  1. ver: Returns the version of  MS-DOS  in use.
  2. cd: Redirects the working directory.
  3. cls: Clear the MS-DOS screen.
  4. copy: Copy files.
  5. del: Delete files.
  6. dir: Displays the contents of a directory.
  7. echo: Display text on the MS-DOS screen.
  8. exit: Exit the program.
  9. md: Create a new directory where the current working location is located.
  10. 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.

Picture 2 of What is a .BAT file? How to create and use BAT files on Windows computers

Step 2: Enter the command

Enter any content, command for the file > Click File > Select Save As.

Picture 3 of What is a .BAT file? How to create and use BAT files on Windows computers

The BAT file has 7 basic commands:

  1. TITLE: The window name for the BAT file.
  2. ECHO: Print command of the BAT file.
  3. 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.
  4. 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.
  5. CLS: Clean the DOS window screen.
  6. IPCONFIG: Network information displayed on DOS.
  7. 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.

Picture 4 of What is a .BAT file? How to create and use BAT files on Windows computers

Finally, you will see your BAT file has a gear shape, the BAT file creation is complete.

Picture 5 of What is a .BAT file? How to create and use BAT files on Windows computers

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.​

Picture 6 of What is a .BAT file? How to create and use BAT files on Windows computers

- 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!

Update 06 July 2021
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile