How to create a .bat file on Windows: step-by-step description, recommendations

As you know, operating systems with graphical user interfaces did not always “host” computers. Even before they appeared, DOS-like operating systems were very often used, in which special commands had to be entered to perform any actions. And it was from them that the principles of creating and executing so-called batch files were borrowed.

Despite the loud statements made by Microsoft that MS-DOS support was discontinued a long time ago, if you think carefully, it’s easy to figure out that the same command line or PowerShell console works on exactly the same principles. And sometimes for them to enter some specific commands that initiate the execution of certain actions is completely optional. You can easily write your own code and save it in a special BAT file, after which the actions will be performed automatically. But how to create a .bat file in Windows 7 or OS lower or higher? There are several simple ways for this, which will be discussed later. But first you need to find out what these objects are and what they can be used for.

What is a batch file?

In general, today there are two main varieties of such files, separating them solely by extension: either BAT or CMD. Since such objects are very similar both in content and in principle of execution, so that there is no confusion, we will consider precisely the issues related to how to create a BAT file in Windows 7 and higher (although the proposed solutions equally apply to earlier modifications).

BAT file logo (icon)

BAT-file, or in common people “batch file”, is the most ordinary text document containing a set of specific commands that are executed sequentially as you move from one line of code to another. However, sets can contain many additional operators, including looping around the execution of an action (loop) or transitions subject to certain conditions (if, goto, etc.). If you look at the second two operators, it will become clear to many that they were used even in such ancient and primitive programming languages, which include the same Basic. Despite this, at the present stage of development of computer technologies, they are also successfully used in more "advanced" languages ​​(for example, when writing scripts in VB or in Pascal).

What are batch files for?

As for the purpose of such files, for the most part they are used to automate some, so to speak, routine processes, most often associated with primitive actions like copying or moving data, sequentially launching several programs, etc. For some reason, it is believed that This is the prerogative of system administrators, but for many users, knowledge about the structure of such objects can also be useful (for example, to run some types of applications in Windows through the command line if The usual start of the EXE file is blocked by the operating system for some reason, or some system setting is unavailable for changes).

Windows batch file examples

We will talk about how to create a .bat file in Windows 10 and below a little later, but for now, to bring final clarity about the most efficient use of such objects in Windows systems, we will consider some interesting examples.

Autoexec.bat file example content

So, probably, all those users who at one time worked with the first modifications of Windows know that they previously had a special Autoexec.bat file that was responsible for the system configuration when it was started, and the user could add the necessary execution commands to it applications like cleaning up disk space, making copies of important data, etc. It was only much later that a special configurator appeared in the system, called by the msconfig command.

Another rather unusual example can be given for tablets based on Windows RT versions 8 and 8.1, in which applications are installed exclusively through the Windows “Store”, and third-party software cannot be installed.

RT_Jailbreak Exploit Batch File

The solution was found and presented by a group of enthusiasts in the form of a small utility RT_Jailbreak 1.20, which contains a “batch file” that allows you to disable the verification of digital signatures of installed applications (without a Microsoft signature, installation is impossible, as well as disabling checks by the system itself, in which such tools are blocked) .

No less interesting are the batch file from the Windows RT Development Toolkit, which allows you to restart the system in developer mode.

Microsoft Digital Signature Batch File

And, of course, the SignTool program turned out to be a very necessary utility, presented just in the form of a BAT-file, which allows executing for any software and its components in the form of executable EXE files and related DLLs, so to speak, “re-signing” with a change in the original Microsoft digitally signed.

How to create a .bat file in Windows via Explorer?

But back to creating batch objects. How to create a .bat file using the built-in file manager of the system? Elementary!

Creating a .bat file through Explorer

Using RMB on an empty space in a given location, select the "Create ..." section, and then go to the point of creating a text document. After it appears in the workspace, you just need to rename the file, giving it an arbitrary name and the corresponding BAT extension through a dot. Please note that when performing such an operation, the display of extensions must be enabled without fail.

How to create a file with the BAT extension in Notepad?

Since, as already mentioned above, the "batch file" is a text file, there is another solution, involving the use of the standard text editor "Notepad". How to create a .bat file in this case? Easy too!

Creating a .bat file in Notepad

Enter the necessary commands, and then use the file menu to save the file, but in the document type, set "All files", and in the name field, enter the desired name with the BAT extension through the dot. User reviews suggest that this method is used most often.

Note: just in case, it is worth noting that the registry files are created in the same way, if necessary.

Using the FAR File Manager

Finally, let’s look at how to create a BAT file in one of the popular file managers called FAR Manager, which was created in the image of Norton Commander.

Creating a .bat file in FAR Manager

To do this, use the key combination Shift + F4, after which the name of the file is entered with the extension through the dot, the enter key is pressed, and the empty file is saved by pressing Shift + F2, which corresponds to the Save As ... command (Save As ...) . You can edit the contents by entering the necessary commands through the corresponding “Edit” function, called by the F4 key. As for the teams, it is better to study them yourself beforehand. But for all those who want, for example, to create a folder through a BAT file, you can offer the MKDIR command or its abridged version of MD FolderName, where FolderName is the name of the directory. By and large, the command can be complicated by specifying the location on the disk and selecting the user. Anyway, for almost all teams, you can apply absolutely any variables that are in teams are percent symbols on both sides.

Epilogue

That’s all about the question of how to create a .bat file on Windows systems using a few simple tools. Which of them is the simplest is up to the user to decide, however, for the convenience of simultaneously creating a "batch file" and editing it, it is best to use either Notepad (or another similar text editor) or FAR Manager.

Source: https://habr.com/ru/post/C11300/


All Articles