Do you find yourself opening the same programs every time you start your computer? Do you always open Command Prompt so you can run the same commands all the time? Learning how to create a BAT file can save you a lot of time by automating these steps.
A BAT file is a special text format with a .bat extension that runs a series of command line commands in the sequence you specify. You can create a BAT file that automates everything you do on the command line.
What can you do with a BAT file?
- Change system settings
- Automate website launches
- Run multiple applications on schedule
- Automate system backups
In this tutorial, you will learn how to create and run your first batch file in Windows 10. You will also learn how to perform advanced automation using the BAT file and how to schedule this automation using the Task Scheduler.
Create a BAT file in three steps
Creating a BAT file in Windows 10 is very easy. All you need is a Notepad. You just need to create a text file with properly formatted BAT commands Then save the file with the .bat extension and run it.
However, there are a few important points to keep in mind along the way, so let’s work on the steps.
– /
In this section, you will learn how to create an automatic BAT file that launches Chrome on your favorite news web page, clears Windows 10 cache for better system performance, and gets the latest weather forecast from the Internet.
Step 1. Create a Simple Batch Startup File
Step 1: Create a simple startup batch file
To create a BAT file in Windows 10, simply select the Start menu, type Notepad and select the Notepad app to open it. Inside Notepad, you will need to enter the following script. You can copy and paste from there to Notepad.
start https://news.google.com
DEL / F / S / Q% TEMP%
finger nashville@graph.no
pause
Save the file somewhere on your computer so it’s easy to find. Many people save their BAT files to C: temp or some simple folder located at the root level of the C: drive
It’s important to change the File Type dropdown menu to All Files. Then don’t forget to add “.bat” at the end of the file name.
This will save the text file as a batch file.
Now open that directory in Windows Explorer and double-click the BAT file you just created. When you do this, you will see the following steps follow in sequence.
- The Google News web page will open using the default browser on your system.
- All files in the Windows temp folder will be deleted.
- The command line will display the weather forecast for the next 24 hours.
You’ve just created your first working BAT file that automates three useful tasks in a row!
However, you are not finished yet. You need to adapt some of these commands to suit your situation. Let’s take a look at what each of these commands do and how you can customize them to suit your needs.
Step 2: Customize your BAT file
Now that you know how to create a BAT file with multiple commands, you need to customize each of these commands according to your needs.
Below is a more detailed explanation of each of these commands and how to configure them.
Launch command
The start command will launch any application you specify. If you use a url like this command, it will use your default browser to open this web page. The following command will launch Google News in your default browser.
start https://news.google.com
You can change the URL so that the command opens any web page you like.
DEL Command
The DEL command is very simple, it deletes one or more files in a given directory. You can use many parameters to tell the command how to behave.
DEL / F / S / Q% TEMP%
There are many parameters you can use to tell the command how to behave.
- / F – enables deletion of read-only files.
- / S – Deletes files in subdirectories, as well as in the current directory
- / Q – “Quiet” mode is required, which does not require confirmation of deletion.
In this example,% TEMP% is used to specify a directory. This is the system environment variable for the Windows temporary files directory.
You can specify any other directory if you want. Or you can list multiple DEL commands and delete files from multiple directories.
Finger Command
The Finger command uses your computer’s Internet connection to connect to any remote computer that is running the finger service.
They are not easy to find, but there is one special service on the graph.no site that allows you to view the 24 hour weather forecast with a simple finger command.
finger nashville@graph.no
With this command, you just need to put the name of the largest nearby city before the @ graph.no part of the web address.
The command returns a graph of the temperature and sunlight level symbols for the next 24 hours.
Pause command
The Pause command pauses execution of your BAT file so you can see any information returned by various commands. This is especially useful after using the Finger command so that you can view the graph.
If you are using other commands and you do not need to see any information returned, you can remove the Pause command at the end of the script.
In fact, if you don’t need to see anything from the script at all, you can add @ECHO OFF as the first line of the BAT file, and you won’t see anything returned by the commands at all.
Step 3: Schedule the batch task
Once you create a BAT file, it won’t do much good unless you manually double-click and run it whenever you want to run automatic commands.
It would be much easier to let the batch job run automatically every day. You can do this by running the BAT file as a Windows Scheduled Task.
To do this, select the “Start” menu, enter “Scheduler” and select “Task Scheduler”.
This will open the Task Scheduler Select “Task Scheduler Library” in the left pane to view all scheduled tasks on your system.
You can add a new scheduled task to run a new BAT file. To do this:
- Select New Task in the Actions pane on the right.
- In the New Task window, General tab, give the task a name in the Name field. Leave all other settings as default.
- Select the Triggers tab. Click the Create button. In the New Trigger window, select Daily and leave all other settings as default. Select OK and then click OK on the New Task window.
- Click the Actions tab and select New. In the New Action window, select Browse and navigate to where you saved your BAT file. Click OK to finish. Click “OK” in the “Create Task” window.
- You should now see the scheduled BAT file in the Task Scheduler library.
Your new scheduled BAT file will now run at the same time every day.
Customize your BAT file
Now that you know how to create and schedule your BAT file, you can start expanding that file by learning about other BAT file commands that you can add to the file.
There are many CMD commands you can add to your BAT file to automate anything on your computer. Start experimenting and see what cool things you can create from your own batch files.
–