How to create a BAT file on Windows to perform quick tasks

BAT Windows On Windows we are used to using only the buttons and menu items to be able to start programs and perform actions on the PC; at the dawn of the Microsoft operating system all the operations took place from the command line or using some simple scripts, so as to be able to obtain a series of commands with a single click. The extension of the created script files was BAT, with which we could combine several command lines into a simple text file executable by any version of Windows (compatibility with BAT files is also maintained on Windows 10, the latest version of the system operating Microsoft).
Recalling from the past, in this guide we will show you how to speed up some common Windows operations without having to use the graphic interface every time, showing you how to create a BAT file and how to start it on the operating system. In addition to the immediate start of the script, we will also show you how to time it, so you can start it at a specific time or after a certain period of time. READ ALSO: Tricks with Windows Notepad (Notes Lock)

How to create a BAT file on Windows

Below we will find everything you need to be able to create a BAT file on any version of Windows still supported by Microsoft (from Windows 7 to Windows 10). On paper, the BAT files are also compatible with older versions of Windows, but we advise you not to use them on them since, being now out of support, they can present major security problems.

How to create a BAT file

To create a BAT file on Windows simply open the Start menu at the bottom left and search for the Block notes.
Block notes

It is our tool with which to create any type of BAT file, appropriately adjusting the file extension (as we will see below). If we want to use a more advanced Notepad program to create BAT files on Windows, we recommend installing the advanced Notepad ++ notepad, open-source and available for free.

Once the preferred notepad is open, we insert one or more command lines into the text field, so that we can start the script compilation. To maintain order and to understand if the script has been executed, we advise you to write on top of it with the following command:

@echo off

this will allow us to visualize the result of the execution, without necessarily showing the commands carried out. Once we have inserted the necessary command lines, we add to the script with the command:

breaks

If we want the window to wait for our confirmation for the closure or, alternatively, we can close the script with the command:

cls

That will immediately close the window as soon as the script is executed. After completing the command, we click on the menu at the top left File, select Save with name, we choose in which folder to save the script, we open the drop-down menu next to the item Save as, we set All files (*. *) and finally we choose a name for the script in the field File name, taking care to also add the extension .bat.
Create BAT

To create the BAT file, simply click on the button at the bottom Save. The script is ready, we’ll just have to double-click on it to start the execution. In the next paragraph, we will show you some ready-made script commands that we can insert between @echo off is breaks, so as to have immediately available some simple scripts.

Operations to be performed on a BAT file

Inside the BAT file, we can insert any command supported by the Windows prompt, but for convenience, we have gathered what can be some simple commands to insert into a BAT file, even just for testing:

@echo off
shutdown –s –f –t 0
breaks

With this script we can start the PC shutdown procedure, without going through the Start menu; next to the main command shutdown there are topics that enhance its effectiveness: -s specifies that we need to shut down the PC, -f forces the shutdown of all active programs and -t allows setting a time frame before execution (with 0 the execution will be immediate, but we can also choose 60, 90, etc. according to need; the time is calculated in seconds).

@echo off
shutdown –r –f –t 0
breaks

Practically identical to the previous command, with the difference that the latter will restart the PC instead of turning it off.

@echo off
shutdown –h –f –t 0
breaks

The command is similar to the previous ones, only it will start hibernating the computer instead of turning it off completely.

@echo off
rd / s c: $ Recycle.Bin
breaks

With the previous command, we can empty the recycle bin by starting the script and confirming with S is Submit on the keyboard to the cancellation request. In order to successfully execute the BAT file, we right-click on it and use the entry Run as administrator.

@echo off
wuauclt.exe / detectnow / updatenow
breaks

With this command, we can search for any Windows updates so that we can download and install them on our computer. In order to successfully execute the BAT file, we right-click on it and use the entry Run as administrator.

@echo off
cd “C: Program Files Windows Defender”
MpCmdRun.exe -SignatureUpdate -MMPC
MpCmdRun.exe -Scan -ScanType 1
breaks

With these commands, we will update the definitions of Windows Defender (the antivirus integrated into Windows 10) and then we will start the quick scan of the whole PC. In order to successfully execute the BAT file, we right-click on it and use the entry Run as administrator.

To create your own scripts we can use MS-DOS commands or command prompt; in the latter case, simply open the Start menu at the bottom left, search for the program Command Prompt, start it and type help, so as to display all the most common commands we can use to create our BAT script.

How to schedule the execution of a BAT file

In addition to using the -t argument to be able to plan the execution of a specific command, we can plan the entire BAT file using the program Scheduler, which we can look for in the Windows Start menu.
Planning

Once the program window is open, right-click on Create activity, in the first screen we choose a name to assign to the activity then let us take the tab Actions, so you can click on the button New.
Add operation

In the new window, make sure it is set in the field Operation the voice Program start, so we click on the button Browse and select the BAT script we created earlier. Once the file is added, click on OK at the bottom, and go to the tab Activation, we press on New and we choose the time conditions under which Windows should automatically run the task.
Add activation

We carefully select the activity in the field Start business, so we choose whether to run the BAT script at regular intervals, at PC startup or at user login. At the end of the configuration we click on OK, we check the other tabs to see if the activation conditions reflect our needs so we create the new planned activity by clicking OK.

Note: if we have created a BAT script that requires administrator permissions to be able to run properly, make sure we check the box next to the entry Run with the highest privileges in the tab General.

Conclusions

With BAT files we can speed up the execution of some common operations such as computer shutdown, reboot and hibernation and some simple maintenance procedures such as emptying the recycle bin and launching an antivirus scan integrated into Windows 10. Obviously we can create a multitude of different BATs based on our needs and our command prompt management capabilities.

If we look for other advanced tricks on how to best use the Windows command prompt, we invite you to read our guide to Command prompt tricks (CMD). Always as a prompt, we can use some very useful control and analysis tools to manage the computer, as described in our article ai 5 useful hidden tools in the Windows command line.

LEAVE A REPLY

Please enter your comment!
Please enter your name here