How To Create Batch File. In this article, you will get to know what is Batch file, how to write a Batch file, how to run Batch file as Administrator, and how to edit a Batch file.
What Is A Batch File?
In your computer, you might have seen file with .bat extesion. These are called Batch Files. These are text files that are saved as .bat extension. Batch files are scripts that contain command lines. These lines can be changed by the Command Prompt. When you execute the batch file, the Command Prompt will run the saved commands in the batch file in sequence.
You can do any task on a PC by just creating a Batch file. It saves a lot of time. You can change system settings, automate routines, and start apps, features, or websites using specific batch files.
How To Create Batch File?
You can create a Batch file easily. You have to write the codes of any particular function in any text editor. Then, you have to save it as a .bat extension. It is all about writing a code. So, you have to learn about the batch script for writing a Batch file. Batch Script is a language use for writing codes to create a batch file in any text editor. Here are some basic commands in the batch script:
ECHO:You can view the working script in the command prompt.
TITLE:You can add the title of the batch script in the Command Prompt.
CLS:It is used to clear the command prompt.
REM:This command is used to share information about the code with each other.
PAUSE:It is a break command. It will stop the logical chain and allow users to read the command lines and proceed with the function.
START “” [website]:This command opens the mentioned website using the default browser.
COPY:It is used to copy files from one location to the other.
EXIT:This command is used to terminate the command prompt window.
There are also many other commands with advanced functions for creating a Batch file.
How To Write A Batch File That Returns “Hello World”?
You have to start with a simple Batch file that returns the “Hello World” value in the Command Prompt. To write the code:
1.First, open Notepad or any other text editor.
2.Enter the following commands:
ECHO OFF
ECHO “Hello World”
PAUSE
3.Save the file with any name but include the .bat extension in the end.
4.This will create the batch file.
5.You will see the following output in the command prompt after running the batch file.
How To Write A Batch File To Run Basic Network Diagnostics?
To avoid running the diagnostic commands to solve network issues, just write a simple batch file to run ipconfig /all, ping and tracert command all at once.
1.Open the Notepad or any other text editor again.
2.Type the following command:
ECHO OFF
ipconfig /all
ping digicruncher.com
tracert digicruncher.com
PAUSE
3.Save the file with .bat extension to create the batch file.
How To Run Batch File As Administrator?
Some command lines need administrative privileges. To run batch file as administrator:
1.Right-click on the batch file on your PC.
2.Select the Run as administrator option from the right-click context menu.
3Click on the Yes option in the UAC prompt.
4.The batch file should run as an administrator.
How To Edit The Batch File?
When you create a complex Batch file, there may be chances that you need to repeatedly edit it to make it work according to your needs. To edit a Batch file:
1.Right-click on the batch file on your PC.
2.Select the Edit option from the right-click context menu.
3.The text editor will open.
4.Now, you will be able to edit the codes.
5.Save the file by press Ctrl + S.