Batch files are one of the simplest ways to make your computer to do things. You can use them to automate your daily tasks, lessen the overall time to do something and convert a tough process into something that anyone can work on.
In this post, we are going to show you on how to create a simple batch file. We will also teach you on what those files can do and how you can write them for yourself by providing additional resources for learning to write batch (BAT) files.
How to create a simple BATCH file?
Step 1: Create a BAT file
When you are facing any network issue, you might open the Command Prompt and type ipconfig and pinging Google or any other site to troubleshoot those programs. After sometime, you realize that all those steps are time consuming and then you decide to write a simple BAT file and save it in your USB drive. So that every time you are facing any network issue in your computer or any other computer, you can just plug in your USB drive and run the BAT file to troubleshoot the network issue in a single click
Create a new Text document
You will have to create a text document. To do so, right click anywhere on the screen and go to New à Text Document.
Double click the Text document that you have created to open the text editor. Copy and paste the code that is provided below.
@echo off title This is your first batch script! echo Welcome to batch scripting! pause
Save the file as BAT file
Now save the file with .bat extension. You can do it by going to File à Save As and then providing the desired name with .bat extension. (Example: welcome.bat). Then click OK to save the file. When you double click on the newly created .bat file, you will see “Welcome to batch scripting!” in the screen.
Try modifying the sentence after the echo command provided in the script above to see how the output reflects accordingly.
Step 2: Few important commands
If you are good at using the command prompt, then you are already an expert in creating the bat files, because, the language is almost the same.
Save up to 60% on Norton Security! Find the product that's right for you- Norton Antivirus Basic, Standard, Deluxe, or Premium.
@echo – This parameter is used for viewing your working code. If you add off after this parameter, it will prompt the script to be closed after it has finished.
title – this works much like the <title> tag in HTML. It provides a title in the command prompt window for the script that you have written.
cls – It is used to clear the command prompt.
rem – This is known as the remark command which works much like the <!- tag in HTML. The sentences that you add using this command are not part of the code in your script. They are used to provide explanation regarding the code.
%%a – Each file in the folder.
(“.\”) – The root folder.
pause – This will provide a break from the logical chain of your .bat file. It is denoted by the phrase, “Press any key to continue…”
start “” [website] – This will open the website in your default web browser.
ipconfig – This is used to display information regarding the network. It will include the IP addresses, sub-net masks and MAC Addresses.
ping – This will ping an IP Address. It is used to gauge the response time using location and latency.
Step 3: Write and Run your BAT file
Do you want to open all the news websites in a single click? You can do it very easily using the bat file. You can also open any of your favorite websites in the similar manner. For example, we are going to add only the news sites.
@echo off start "" http://www.cnn.com start "" http://www.abc.com start "" http://www.msnbc.com start "" http://www.bbc.com start "" http://www.huffingtonpost.com start "" http://www.aljazeera.com start "" https://news.google.com/
Create a Bat file according and name it as you wish with the .bat extension. Then past the code that is provided above.
Once the file is saved, double-clicking it will open all the news sites in your default web browser.
Automate a lot of tasks
You can automate a lot of repeated tasks which you do daily using the simple scripts. The more you use the batch files, the more you are automating the tasks in your machine.
Let us know whether the commands written above are working in your desktop/laptop. We’d love to hear about it from you.
You might also like our TUTEZONE section which contains exclusive tutorials on how you can make your life simpler using technology.