What is a windows batch file?
Batch file is a script file in DOS, OS and Microsoft Windows. It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. A batch file may contain any command the interpreter accepts interactively and use constructs that enable conditional branching and looping within the batch file, such as IF, FOR, and GOTO labels. The term “batch” is from batch processing, meaning “non-interactive execution”, though a batch file may not process a batch of multiple data.
A batch file or batch job is a collection, or list, of commands that are processed in sequence often without requiring user input or intervention. With a computer running a Microsoft operating system such as Windows, a batch file is stored as a file with a .bat file extension. Other operating systems may define a batch job in a shell script, containing a list of commands to be executed one after the other. Batch files are often used to help load programs, run multiple processes at a time, and perform common or repetitive tasks.
A BAT file is a DOS batch file used to execute commands with the Windows Command Prompt (cmd.exe).BAT files are also called batch files, scripts, batch programs, command files, and shell scripts, and may instead use the .CMD extension. It contains a series of line commands in plain text that are executed to perform various tasks, such as starting programs or running maintenance utilities within Windows. Software of all types use .BAT files for various purposes—for example, to copy or delete files, run applications, and shut down processes.
A file with the .BAT file extension is a batch processing file. It’s a plain text file that contains various commands used for repetitive tasks or to run groups of scripts one after another.
Create and run batch file on Windows:
In this guide, we’ll show you how to write and execute batch files to automate tasks. On Windows, a batch file typically has a “.bat” extension, and it is a special text file that includes one or multiple commands that run in sequence to perform various actions with Command Prompt. You can also use other tools like PowerShell to write even more advanced scripts. However, running batch files in Command Prompt is still relevant to execute commands to change settings, automate routines, and start apps or launch websites on your device.
In this guide, we will walk you through the steps to create and run a batch file.
Steps to create a batch file on Windows:It is a simple process to create a batch file. You need only a text editor and some basic knowledge of Command Prompt. steps to create a basic and advanced batch file and write a script to change system settings. use these steps:
- Open Start.
- Search for Notepad and click the top result to open the text editor.
- Type the following lines in the text file to create a batch file:
- The above script outputs the phrase, “Congratulations! Your first batch file was executed successfully,” on the terminal screen.
- Click the File menu.
- Select the Save as option.
- Confirm a name for the script for example, first_basic_batch.bat.
- Once you complete the steps, you can double-click the file to run it.
Steps to run a batch file on Windows:
On Windows, there are at least three different ways to write batch files. You can run them on-demand using Command Prompt or File Explorer. To run a script file with Command Prompt on Windows , use these steps:
- Open Start.
- Search for Command Prompt, right-click the top result, and select the Run as administrator option.
- Type the following command to run a batch file and press Enter: C:\PATH\TO\FOLDER\BATCH-NAME.bat
After you complete the steps, the console will return the results, and the window won’t close even if the script does not include the “PAUSE” command since you are invoking the script from within a console window that you opened manually.
Using File Explorer:
To run a batch file with the Windows 10 File Explorer application, use these steps:
- Open File Explorer.
- Open the folder containing the batch file.
- Double-click the script file to run it.
- (Optional) If a command requires administrator privileges, you will need to run the script as an admin by right-clicking the file and selecting the Run as administrator option.
- Click the Yes button.
Here some basic commands of batch file:
echo – Prints out the input string. It can be ON or OFF, for ECHO to turn the echoing feature on or off. If ECHO is ON, the command prompt will display the command it is executing.
cls – Clears the command prompt screen.
title: Changes the title text displayed on top of prompt window.
EXIT – To exit the Command Prompt.
pause – Used to stop the execution of Windows batch file.
:: – Add a comment in the batch file.
COPY – Copy a file or files
Types of “batch” files in Windows operating system:
- INI (.ini) – Initialization file. These set the default variables for the system and programs.
- CFG (.cfg) – These are the configuration files.
- SYS (.sys) – System files, can sometimes be edited, mostly compiled machine code in new versions.
- COM (.com) – Command files. These are the executable files for all the DOS commands. In early versions there was a separate file for each command. Now, most are inside COMMAND.COM.
- CMD (*.cmd) – These were the batch files used in NT operating systems.
I hope this article is helpful to you.