How to set up smartphones and PCs. Informational portal
  • home
  • Interesting
  • How to register a bat file. Writing bat files - examples of batch files

How to register a bat file. Writing bat files - examples of batch files

As you know, operating systems with graphical user interfaces did not always "dominate" computers. Even before their appearance, 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 from Microsoft that support for MS-DOS was discontinued a long time ago, if you think about it, it is not difficult to realize that the same command line or PowerShell console works exactly according to the same principles. And for them sometimes it is completely unnecessary to enter some specific commands that initiate the execution of certain actions. 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 to do 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 types of such files, dividing them exclusively by extension: either BAT or CMD. Since such objects are very similar to each other both in content and in the principle of execution, so that there is no confusion, we will consider exactly 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, or in the 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 statements, including looping the execution of an action (loop) or jumps with the observance of any conditions (if, goto, etc.). If you look at the second two operators, it will become clear to many that they were used in such ancient and primitive programming languages, to which the same Basic can be attributed. Despite this, even at the present stage of development of computer technologies, they are successfully used in more "advanced" languages ​​(for example, when writing scripts in VB or in Pascal).

What are we for

As for the purpose of such files, most of them are used to automate some, if I may say so, routine processes, most often associated with primitive actions such as copying or moving data, sequentially launching several programs, etc. For some reason, it is believed that this is the prerogative of system administrators, however, knowledge of the structure of such objects can also be useful to many users (for example, to launch some types of applications in the Windows environment through the command line, if the usual start of an EXE file is blocked for some reason by the operating system, or some the system setting is unavailable for modification).

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, in order to make the final clarity about the most effective use of such objects in Windows systems, consider a few interesting examples.

So, probably, all those users who at one time worked with the first modifications of Windows know that they previously contained a special file Autoexec.bat, responsible for the system configuration at startup, and the user himself could add commands to execute the necessary applications such as 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 cited for tablet PCs 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.

A 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 verification of digital signatures of installed applications (installation is impossible without a Microsoft signature, as well as disabling checks by means of the system itself, in which such tools are blocked) ...

The batch file from the Windows RT Development Tool set, which allows you to restart the system in developer mode, looks no less interesting.

And, of course, the SignTool program turned out to be a very necessary utility, presented just in the form of a batch BAT file, which allows you to perform for any software and its components in the form of EXE executable files and accompanying DLL libraries, so to speak, "re-signing" with a change in the original digital signature for Microsoft signature.

How to create a BAT file in Windows using Explorer?

But back to creating batch objects. How do I create a BAT file using the system's built-in file manager? Elementary!

Through the 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, assigning it an arbitrary name and the corresponding BAT extension separated by a dot. Please note that when performing such an operation, the display of extensions must be enabled without fail.

How do I create a BAT file in Notepad?

Since, as it was said above, the "batch file" is a text file, there is one more solution, which involves the use of the standard text editor "Notepad". How do I create a BAT file in this case? Simple too!

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

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

Using the FAR file manager

Finally, let's take a look at how to create a BAT file in one of the popular file managers called FAR Manager, which was modeled after Norton Commander.

To do this, use the Shift + F4 key combination, after which the file name with the extension separated by a dot is entered in the file name field, the enter key is pressed, and the empty file is saved by pressing Shift + F2, which corresponds to the "Save As ..." command ... You can edit the content by entering the necessary commands through the corresponding function "Edit", called by the F4 key. As for the commands, it is better to study them yourself in advance. But all those who want, for example, to create a folder through a BAT file, can be offered the MKDIR command or its abbreviated version MD FolderName, where FolderName is the name of the directory. Generally speaking, the command can be complicated by specifying a location on the disk and selecting a user. And in general, for almost all commands, absolutely any variables can be used, which in commands are enclosed in percent symbols on both sides.

Epilogue

That's all for the question of how to create a BAT file on Windows systems using a few simple tools. It is up to the user to decide which of them is the simplest, but for the convenience of both creating a batch file and editing it, it is best to use either Notepad (or another similar text editor) or FAR Manager.

People who are familiar with the term batch file know that BAT files can significantly simplify their lives and save time if they know how to write and use them correctly. In this article, I will talk about how to create BAT files and introduce you to the common mistakes that usually occur when writing them.

It is very easy to create a BAT file. It is enough to open notepad and save a blank sheet with the .bat extension by selecting the Save as ... option and writing something ending in .bat in the File name field, for example test.bat.
Specify the file type as in the screenshot below - All files. Save and receive the BAT file.

You can edit the BAT file in notepad or any other text editor focused on working with code.

Now let's go directly to the practical information. On the net, many are looking for an answer to the question How to deal with spaces in BAT files? ... The presence of a space in the paths to folders and executable files causes an error. The most common answer is: Enclose the path in quotation marks. And this answer is not correct. True, some will argue with foaming at the mouth that it works. So, there were two why - why is not true and why some will.

On Windows (as well as on UNIX), programs installed on the system are properly registered by the system. Therefore, some of the installed programs can be launched with one simple command from the BAT file or from the Run applet of the Start panel. One of these programs is Firefox:

start firefox

If after this command you write the path to the executable file, the following happens: Firefox starts and tries to process the request, that is, the file, the path to which is specified. That is, if you specify the following:

start firefox C: \ Program Files \ Mozilla Firefox \ firefox.exe

The browser will open so it doesn't write after start firefox. That is why some comrades will assure that everything works great. However, if you take a portable program, the situation is completely different. Let's take a Filezilla ftp client as an example. Since the system is unaware of the program, the above line is

start filezilla

will not work. To run a program unknown to the system, you must specify the path to it:

start D: \ FileZilla \ FileZilla.exe

Long names in bat files

Now let's talk about paths and spaces. The first way to avoid this problem is to use a short name.

start C: \ Program Files \ Sound Club \ scw.exe

In the example, there are two names with spaces. Let's replace them with short ones. The rules for creating short names are as follows: the short name uses the first six characters of the name without regard to spaces, after the name indicate the ordinal number of the folder using the symbol ~ ... Since the Program Files and Sound Club folders are in the singular, the following will turn out:

Program Files - Progra ~ 1 Sound Club - SoundC ~ 1 start C: \ Progra ~ 1 \ SoundC ~ 1 \ scw.exe

If there are two folders nearby, for example Sound Club and Sound Clown, then following the rules, in the example above, you will need to specify SoundC ~ 2, since in this case Sound Club will be the second name (names are considered in alphabetical order).

But this method is inconvenient in that you have to specify serial numbers. The situation with Program files is less normal. Few people have two similar folders on the system disk. But if you decide to install multiple Mozilla products on your computer. You will end up with several folders, for example:

Mozilla Firefox Mozilla Thunderbird Mozilla Sunbird

Short names for them will be

Mozill ~ 1 Mozill ~ 2 Mozill ~ 3

Now imagine that you have written a BAT file mentioning these programs. If you uninstall Firefox, the remaining entries will stop working, and if you uninstall Thunderbird, the entry for Sunbird will stop working. In short, the way with short names is not our way.

Spaces and quotes in bat files

Quotes do work, but not in the ways that are usually advised. Usually the following is advised:

start "C: \ Program Files \ Sound Club \ scw.exe"

So the command will not work, because if you look at the help for it (start /?), Then in the help you will see the following:

START ["title"] [command / program] [parameters]

As you can see, the first parameter is the title of the window and it is just in quotes. This parameter is optional, but it is still advised to specify it () to avoid errors when executing the command. You don't have to write anything inside the quotes. It turns out like this:

start "" "C: \ Program Files \ Sound Club \ scw.exe"

The option of enclosing all names with spaces separately in quotes will also work:

start C: \ "Program Files" \ "Sound Club" \ scw.exe

However, in some cases, none of the above works. In such cases, I can advise using the cd command. Go to the system partition, then use cd to the Program Files folder and run the program (start):

% SystemDrive% cd \ Program Files \ Sound Club \ start scw.exe

I think this method will work everywhere. Now a couple more important points. Let's say you have created a batch file that launches three programs and you need to temporarily exclude the launch of one of the three. This can be done by deleting the line or by commenting it out. The first method is vandal, and the second, see below.

start firefox start jetaudio rem start defraggler

In this case, the launch of the Defraggler.exe program installed on the system is disabled. Comment out lines by specifying the rem command at the beginning of the line. All BAT files are executed in the console window. To make it disappear at the end of the execution of the commands, do not forget to write the command at the end to the exit exit.

start firefox start jetaudio rem start defraggler exit

Running applications from a bat file

In the first part of the article, I gave a general overview of BAT files. Now it became clear - what it is and what it is eaten with. In the second part, we will talk about more specific things. For example, how to run several applications with certain settings using a BAT file, or install the program in automatic mode so as not to waste time on answers like Do you agree with the terms of the license agreement? and do not press unnecessary buttons.

Above, there were several ways to launch applications using a BAT file. The very first is a short command to launch the program installed on the system.

start firefox

It doesn't always work. Therefore, this technique can be fully applied on a specific system, but it is not suitable as a universal solution. If your goal is to make the BAT file work everywhere and always, you need to use full paths:

start C: \ "Program Files" \ "Mozilla Firefox" \ firefox.exe

I also noted that the completion command must be present in the BAT file:

start C: \ "Program Files" \ "Mozilla Firefox" \ firefox.exe exit

Running programs in bat-files with parameters (keys)

You can not just run the program, but give it additional commands at startup. For example, command to run minimized:

start / min D: \ FileZilla \ FileZilla.exe exit

To command in this case means to specify the key. The key is specified with a slash after the main command (command / key). The main command in this case is start. True, the min key works only in half of the cases, because it refers specifically to the start command, and not to the programs that this command starts.

In general, there are a lot of keys and the sets of keys for different programs can differ significantly. There are, however, a few in common. For example, the help key (/? Or / help). To see how this key works, let's look at a practical example. Open the console (Click + R, enter cmd, then Enter) and type the following in the console:

start /?

The console will display a list of valid keys with comments for the start command.

Pay attention to the / wait switch. In some cases, it is simply irreplaceable. For example, you decided to use the BAT file to unpack the archive with the program and run this very program. The batch file will contain two commands - for unpacking and for launching. Since the commands when starting the BAT file will be executed almost simultaneously, the archive will not have time to unpack and there will be nothing to launch. Therefore, there will be an error. In this case, the key will come to the rescue. / wait:

Thus, the system will first perform the first action, wait for its completion, and only then proceed to the second. If you need to wait for a specific period of time, then it is easier to use the console utility. In the right place in the BAT file, write the following command (number - number of seconds):

start Sleep.exe 15

You can do a lot with keys. It is possible to install applications. For this, several keys are used, depending on the type of installer used to install the program on the computer:

/ S / s / q / silent and several others

In some cases it is very convenient. Avast Antivirus has a silent installation option in the corporate version. The free (home) version supposedly does not have a quiet installation. However, if you know how the InstallShield installer works, you will know that this is a duck, since this installer itself supports the / S silent installation switch. This means that all products made on its basis are the same. And Avast is no exception. Just create a BAT file in the Avast folder with the content

start avast.exe / S exit

run it and the program is installed on your computer with little or no input from you. Thus, you can write a whole list of programs for silent installation and save time, for example, on reinstalling the system. In the article you can get more detailed information on the keys.

There are other possibilities for managing programs using BAT files. You can start a program by telling it to open the file on startup. I use this method when developing sites. It is very convenient when all your tools open the necessary documents and folders with the click of just one button:

rem connection to ftp server start / min D: \ FileZilla \ FileZilla.exe "ftp: // login: password @ server" rem opening index.php in Firefox start C: \ "program files" \ "mozilla firefox" \ firefox.exe "http: //localhost/site_folder/index.php" rem opening start.html in a text editor start / min C: \ "Program Files" \ text_editor.exe "E: \ server \ site_folder \ index.html" rem opening folder with site files start / min E: \ server \ site_folder rem exit console exit

Note that all of the above techniques can be used in various combinations and combinations.

start / min / wait program.exe / m / S start C: \ Directory \ program2.exe "C: \ Files \ file.odt" exit

But it is important to remember: everything related to the execution of the program launched in the batch file is written with it in one line.

start C: \ "program files" \ "mozilla firefox" \ firefox.exe "http: //localhost/site_folder/index.php"

As an epilogue, I will offer for review a converter of BAT files into applications in the .exe format -. A BAT file is not always aesthetically pleasing, and with the help of a converter you can pack a batch file into an exe "schnick, decorating it with any icon of your choice.

I came across another BAT to EXE converter, you can consider it as an alternative to the previous program: Advanced Bat To Exe Converter

Greetings! Today I decided to tell you about baht files, or batch files, as they are called in a simple way. I suppose that the use of baht files will be useful for every computer user, expand the capabilities and simplify many tasks.

What is baht and why is it needed?

Bat is the file extension (bat). Surely many users know that each file has its own extension. This is the last line after the period in the title. It is this "tail" that is needed for the system to define it as music, video, image or any other. You can even experiment. Take any picture and rename it along with the extension. Windows will immediately notify you that you are changing the extension, and the file may not be detected by the system. Agree to the request and you will see that your picture is no longer displayed as an image. If you rename as before, everything will be restored again. If you do not see the extensions, you need to activate this function in the explorer, in the "view" tab.

For Windows, a baht is a file with instructions for certain actions that are contained in the baht file itself. An empty baht file will run, but no action will be taken. Batnik is a set of instructions for the Windows console.

How to create a baht file to run the program?

To create a batch file, you need to start the text editor, then save the file with the final name bat. If your editor does not have a save function with such an extension, then you need to register it yourself. When you run such a file, the console will open and if there are no commands, it will immediately close.

Now let's give a command to run the program. To do this, you need to open our created batch file in notepad or another editor and write the command.

Let's start a browser for example. You must first enter the Start command and write Opera after a space.

It should look like this:

Start Opera

This will work for programs known to the system, but if you launch software that is not known to the system, you will need to register the entire path to the program. For example, if you have ftp installed in the Program Files folder, then in order to start it you need to enter the command

start filezilla

And if the ftp client is installed in a different folder, you will need to register the entire path.

The scope of body shirts is quite wide. A variety of commands can be added to the configuration. You can find them out on the Internet, if you are interested in more detailed information on the commands, write in the comments, I will try to answer you. VBS works in a similar way. This is the same, only the execution of commands is not through the console, and the commands are slightly different.

This technology will help you to perform all sorts of tasks, and in an automatic mode. Some users even write viruses this way. To make it impossible to change the configuration of the file using a text editor, you need to convert the bat file to exe. This will help make various auxiliary software that you can find on the net. For example, to convert bat to exe, the Bat to exe converter program will help.

The baht function is very useful and sometimes necessary. With it, you can write entire programs with a narrow spectrum of action. The scope depends only on the knowledge of the teams and the ability to combine them. Therefore, use and expand your skills and ability to use a computer at the Super User level.

People who are familiar with the term batch file know that BAT files can significantly simplify their lives and save time if they know how to write and use them correctly. In this article, I will talk about how to create BAT files and introduce you to the common mistakes that usually occur when writing them.

It is very easy to create a BAT file. It is enough to open notepad and save a blank sheet with the .bat extension by selecting the Save as ... option and writing something ending in .bat in the File name field, for example test.bat.
Specify the file type as in the screenshot below - All files. Save and receive the BAT file.

You can edit the BAT file in notepad or any other text editor focused on working with code.

Now let's go directly to the practical information. On the net, many are looking for an answer to the question How to deal with spaces in BAT files? ... The presence of a space in the paths to folders and executable files causes an error. The most common answer is: Enclose the path in quotation marks. And this answer is not correct. True, some will argue with foaming at the mouth that it works. So, there were two why - why is not true and why some will.

On Windows (as well as on UNIX), programs installed on the system are properly registered by the system. Therefore, some of the installed programs can be launched with one simple command from the BAT file or from the Run applet of the Start panel. One of these programs is Firefox:

start firefox

If after this command you write the path to the executable file, the following happens: Firefox starts and tries to process the request, that is, the file, the path to which is specified. That is, if you specify the following:

start firefox C: \ Program Files \ Mozilla Firefox \ firefox.exe

The browser will open so it doesn't write after start firefox. That is why some comrades will assure that everything works great. However, if you take a portable program, the situation is completely different. Let's take a Filezilla ftp client as an example. Since the system is unaware of the program, the above line is

start filezilla

will not work. To run a program unknown to the system, you must specify the path to it:

start D: \ FileZilla \ FileZilla.exe

Long names in bat files

Now let's talk about paths and spaces. The first way to avoid this problem is to use a short name.

start C: \ Program Files \ Sound Club \ scw.exe

In the example, there are two names with spaces. Let's replace them with short ones. The rules for creating short names are as follows: the short name uses the first six characters of the name without regard to spaces, after the name indicate the ordinal number of the folder using the symbol ~ ... Since the Program Files and Sound Club folders are in the singular, the following will turn out:

Program Files - Progra ~ 1 Sound Club - SoundC ~ 1 start C: \ Progra ~ 1 \ SoundC ~ 1 \ scw.exe

If there are two folders nearby, for example Sound Club and Sound Clown, then following the rules, in the example above, you will need to specify SoundC ~ 2, since in this case Sound Club will be the second name (names are considered in alphabetical order).

But this method is inconvenient in that you have to specify serial numbers. The situation with Program files is less normal. Few people have two similar folders on the system disk. But if you decide to install multiple Mozilla products on your computer. You will end up with several folders, for example:

Mozilla Firefox Mozilla Thunderbird Mozilla Sunbird

Short names for them will be

Mozill ~ 1 Mozill ~ 2 Mozill ~ 3

Now imagine that you have written a BAT file mentioning these programs. If you uninstall Firefox, the remaining entries will stop working, and if you uninstall Thunderbird, the entry for Sunbird will stop working. In short, the way with short names is not our way.

Spaces and quotes in bat files

Quotes do work, but not in the ways that are usually advised. Usually the following is advised:

start "C: \ Program Files \ Sound Club \ scw.exe"

So the command will not work, because if you look at the help for it (start /?), Then in the help you will see the following:

START ["title"] [command / program] [parameters]

As you can see, the first parameter is the title of the window and it is just in quotes. This parameter is optional, but it is still advised to specify it () to avoid errors when executing the command. You don't have to write anything inside the quotes. It turns out like this:

start "" "C: \ Program Files \ Sound Club \ scw.exe"

The option of enclosing all names with spaces separately in quotes will also work:

start C: \ "Program Files" \ "Sound Club" \ scw.exe

However, in some cases, none of the above works. In such cases, I can advise using the cd command. Go to the system partition, then use cd to the Program Files folder and run the program (start):

% SystemDrive% cd \ Program Files \ Sound Club \ start scw.exe

I think this method will work everywhere. Now a couple more important points. Let's say you have created a batch file that launches three programs and you need to temporarily exclude the launch of one of the three. This can be done by deleting the line or by commenting it out. The first method is vandal, and the second, see below.

start firefox start jetaudio rem start defraggler

In this case, the launch of the Defraggler.exe program installed on the system is disabled. Comment out lines by specifying the rem command at the beginning of the line. All BAT files are executed in the console window. To make it disappear at the end of the execution of the commands, do not forget to write the command at the end to the exit exit.

start firefox start jetaudio rem start defraggler exit

Running applications from a bat file

In the first part of the article, I gave a general overview of BAT files. Now it became clear - what it is and what it is eaten with. In the second part, we will talk about more specific things. For example, how to run several applications with certain settings using a BAT file, or install the program in automatic mode so as not to waste time on answers like Do you agree with the terms of the license agreement? and do not press unnecessary buttons.

Above, there were several ways to launch applications using a BAT file. The very first is a short command to launch the program installed on the system.

start firefox

It doesn't always work. Therefore, this technique can be fully applied on a specific system, but it is not suitable as a universal solution. If your goal is to make the BAT file work everywhere and always, you need to use full paths:

start C: \ "Program Files" \ "Mozilla Firefox" \ firefox.exe

I also noted that the completion command must be present in the BAT file:

start C: \ "Program Files" \ "Mozilla Firefox" \ firefox.exe exit

Running programs in bat-files with parameters (keys)

You can not just run the program, but give it additional commands at startup. For example, command to run minimized:

start / min D: \ FileZilla \ FileZilla.exe exit

To command in this case means to specify the key. The key is specified with a slash after the main command (command / key). The main command in this case is start. True, the min key works only in half of the cases, because it refers specifically to the start command, and not to the programs that this command starts.

In general, there are a lot of keys and the sets of keys for different programs can differ significantly. There are, however, a few in common. For example, the help key (/? Or / help). To see how this key works, let's look at a practical example. Open the console (Click + R, enter cmd, then Enter) and type the following in the console:

start /?

The console will display a list of valid keys with comments for the start command.

Pay attention to the / wait switch. In some cases, it is simply irreplaceable. For example, you decided to use the BAT file to unpack the archive with the program and run this very program. The batch file will contain two commands - for unpacking and for launching. Since the commands when starting the BAT file will be executed almost simultaneously, the archive will not have time to unpack and there will be nothing to launch. Therefore, there will be an error. In this case, the key will come to the rescue. / wait:

Thus, the system will first perform the first action, wait for its completion, and only then proceed to the second. If you need to wait for a specific period of time, then it is easier to use the console utility. In the right place in the BAT file, write the following command (number - number of seconds):

start Sleep.exe 15

You can do a lot with keys. It is possible to install applications. For this, several keys are used, depending on the type of installer used to install the program on the computer:

/ S / s / q / silent and several others

In some cases it is very convenient. Avast Antivirus has a silent installation option in the corporate version. The free (home) version supposedly does not have a quiet installation. However, if you know how the InstallShield installer works, you will know that this is a duck, since this installer itself supports the / S silent installation switch. This means that all products made on its basis are the same. And Avast is no exception. Just create a BAT file in the Avast folder with the content

start avast.exe / S exit

run it and the program is installed on your computer with little or no input from you. Thus, you can write a whole list of programs for silent installation and save time, for example, on reinstalling the system. In the article you can get more detailed information on the keys.

There are other possibilities for managing programs using BAT files. You can start a program by telling it to open the file on startup. I use this method when developing sites. It is very convenient when all your tools open the necessary documents and folders with the click of just one button:

rem connection to ftp server start / min D: \ FileZilla \ FileZilla.exe "ftp: // login: password @ server" rem opening index.php in Firefox start C: \ "program files" \ "mozilla firefox" \ firefox.exe "http: //localhost/site_folder/index.php" rem opening start.html in a text editor start / min C: \ "Program Files" \ text_editor.exe "E: \ server \ site_folder \ index.html" rem opening folder with site files start / min E: \ server \ site_folder rem exit console exit

Note that all of the above techniques can be used in various combinations and combinations.

start / min / wait program.exe / m / S start C: \ Directory \ program2.exe "C: \ Files \ file.odt" exit

But it is important to remember: everything related to the execution of the program launched in the batch file is written with it in one line.

start C: \ "program files" \ "mozilla firefox" \ firefox.exe "http: //localhost/site_folder/index.php"

As an epilogue, I will offer for review a converter of BAT files into applications in the .exe format -. A BAT file is not always aesthetically pleasing, and with the help of a converter you can pack a batch file into an exe "schnick, decorating it with any icon of your choice.

I came across another BAT to EXE converter, you can consider it as an alternative to the previous program: Advanced Bat To Exe Converter

Do you want to extend the life of your computer? Then, to save system resources, create various useful programs and utilities. You can run them with only one batch file.


Users of Windows computers often encounter files that have the .bat extension. These are the so-called batch files. What are they intended for, how are they created and modified, what problems do users have when working with batch files?

What is a bat file? What is it for

Bat file is a text file with a specific set of characters that are entered into the command line. By launching just one file, the user saves time on performing a large number of actions. Such files are used to automate frequently repeated user actions. A .bat file is called a batch file. In the slang of users, it is called "batch file".

Sample bat files

There are many useful bat files with which you can control the computer system, run viruses, steal personal data.
Examples of some popular executable files:
  • Removing empty folders and subfolders on the computer from where the file was launched - for / f "usebackq delims =" %% d in ("" dir / ad / b / s | sort / R "`) do rd "%% d"
  • Remember! If there are hidden files with the .ini or .ini extensions in the folder, the folder cannot be deleted.
  • Transferring information files to subfolders with the date of the operation - SET FOLDER =% DATE: ~ -4% -% DATE: ~ 3.2% -% DATE: ~ 0.2%
    SET ARCFOLDER = Z: \ _ exchange \% FOLDER% mkdir% ARCFOLDER%
  • Programming the delay of subsequent commands for the required time - choice / N / T: y,% sec%> nul
  • Starting a file in a minimized window - start / m / w% path \ file%
Thousands of different bat files help programmers and users to communicate with the computer, find ways out of a wide variety of situations, cleanse the system from viruses and malicious codes. The process of writing scripts for batch files entirely depends on the imagination of the users.

How to open a file with a bat extension

By launching such a file, you can open and close many programs. Some of these are not used in later versions of Windows.
Examples of tasks that can be solved by running the .bat file:
1. Activation of one or more utilities that perform functions within the system - a timer for turning on and off the computer, automatically freeing the clipboard from outdated information, organizing access points for Wi-Fi. The first command is start "" program_path. If there are spaces, you must enclose the path in quotation marks start "" "C: \ Program Files \ program.exe".
Next, you should specify the startup parameters start "" c: \ windows \ notepad.exe file.txt. There is one peculiarity in the startup process. If you do not use double quotes when specifying the name of the command file, then the execution of commands may occur incorrectly.
2. From an already open file, you can start another one by typing the command call path_to_bat_file parameters. Information about them is in another bat file: call file2.bat parameter1 parameter2 parameter3.
The following commands are used to activate other programs:
  • echo% 1
  • echo% 2
  • echo% 3
  • pause
After all performed operations, all transferred parameters appear on the display. If no other order of operations is entered, the command window is automatically closed. The pause command stops the program and closes the operating window.

How do I create a bat file on Windows? Sequencing

The easiest way to create a bat file is to use NotePad. After activating the program from the "Standard" panel or using the command C: \ Windows \ notepad.exe, the code is entered or copied into the notepad page.

In NotePad, the file must be stored with the .bat extension. Care must be taken to ensure that the file you are saving is of the All Files type.


Important! If it is impossible to save a bat file in a specific folder because the user does not have administrator rights, the message "You do not have permission to save files in this location" is displayed on the computer display. Change the location of the file to Desktop or Documents. After that, using copying, transfer it to the desired location on your computer. Bat file is created.

Is it possible to modify the bat file

Bat files can be edited to change various parameters. This can be achieved in several ways.
First. Open the context menu and select the Change command. The necessary edits are made to the file in any text editor installed on the computer.


Second. Also done using NotePad. You need to open "Explorer", find the file and drag it with the mouse to the workspace.


Third. Go to Notepad, in the "File" menu, find the desired folder with the batch file.


Next, change the option for displaying files so that "All files" is active. After that, you can open the file and edit it by changing the required parameters and commands.


Remember! When using any of the above editing methods, the final file must be saved using the "All files" extension. Otherwise, the computer will save the modified file as a text file - * .txt.

You need to run the bat file as administrator

To run the file as an administrator, you need to right-click on the name and execute the "Run as administrator" command.

There are several other ways to run a batch file.
1. After pressing the START button (WIN or the combination Ctrl + Shift + Esc), you must:
  • switch to Latin and type the command .bat on the keyboard.
  • select the executable file * .exe.
  • run the file with the command "Run as administrator"
2. Open the task manager (Ctrl + Shift + Esc or Ctrl + Alt + Delete), on the "Processes" tab, select the "Show processes of all users" command. In the "File" menu, use the Ctrl + Left click to click on the "New task" tab, then click Run.
3. With the display of file types enabled, you can create a * .txt file, name it whatever you want and change the extension to .bat.

Why won't the bat file start? Possible reasons

The most probable reasons for the lack of reaction of the computer to the execution of a command file with the .bat extension or its incorrect operation after launch:
  • incorrect writing of commands in scripts
  • incorrect use of punctuation marks
In most cases, this happens when you carelessly change the keyboard layout from Latin to Russian. Batch files do not accept Cyrillic. The places where the Russian font appears in the script are incomprehensible to the computer. Quite naturally, the bat file execution path changes.

How to create a bat file: video

For a video tutorial on creating a file with the .bat extension, see here:

Top related articles