SoFunction
Updated on 2025-04-10

Recommend a most complete and user-friendly tutorial on batch processing page 2/3


Don’t be scared by this pile of things first, calm down and take a closer look (recalling how the first paragraph of Chapter 1 was written!!). The explanation of each line of command has been given. The content after the two colons is explained by the E-text (you don’t have to worry about those who are afraid of E-text. They are all very easy and you can understand it at a glance. If you really don’t understand it, you won’t look up the dictionary. Are you so lazy?) will not be displayed when the script is executed and will not have any effect. There is a colon at the beginning of the fifth line at the end, which is not a typo! The specific functions will be discussed in detail later. In this script, masm and link are assemblers and linkers, and must be in the current directory along with the edit program and the source code you want to edit (of course, this script, nonsense!). Using this batch script, manual input can be reduced to the maximum possible possibility. During the whole process, you only need to press the Enter key a few times to realize the automatic conversion from assembly source code to executable exe file, and it has intelligent judgment function: if there is an error in the source code during assembly (assembly unsuccessful), the error message will be automatically paused, and the editing source code interface will be automatically entered; if the source code assembly is successful, the generated exe file will be automatically executed after the connection. In addition, due to the simplicity and flexibility of batch processing commands, this script is also good to improve, and simple modification can be in line with the computer-based habits of different friends. Friends who are studying compilation, please don’t forget to have an internship!

The following commands appear in this script: @, echo, ::, pause, : and goto, % and if. And this chapter will tell about these commands.

1、@ 

Everyone is familiar with this symbol. How can it run into batch processing for email? Haha, it’s not its fault. Batch processing is inseparable from it, otherwise it would be imperfect. Its purpose is to make the execution window not display the command itself (what a twisted sentence!). Haha, in layman's terms, if it is available at the beginning of the line, the commands on this line will not be displayed. In Example 5, in the first line of @echo off, the function of @ is to prevent the script from displaying the subsequent echo off part when executing. Do you understand now? Still don't understand it very much? It doesn't matter, after reading the introduction of echo commands, you will naturally understand.

2、echo 

In Chinese, it means "feedback" and "echo". It is actually a switch command, which means that it has only two states: on and off. So there are two commands: echo on and echo off. Execute the echo command directly to display the current echo command status (off or on). Execution of echo off will turn off echo. All commands following it do not display the command itself, only the result after execution is displayed, unless the echo on command is executed. In Example 5, the @ command and the echo off command on the first line are combined to achieve two purposes: not display the echo off command itself, and not display the command itself in the subsequent lines. It's indeed a bit messy, but if you practice it, you can get it in 3 minutes, and you won't get it back!

Another usage of the echo command: You can use it to display information! For example, the second to last line in five, Default BAT file name is  will be displayed in the window after the script is executed, while the echo command itself is not displayed (why??).
Another usage of the echo command is 2: You can edit text files directly. Example 6:
echo nbtstat -A 192.168.0.1 >  
echo nbtstat -A 192.168.0.2 >>  
echo nbtstat -A 192.168.0.3 >>  

The method of editing the above script content is to directly enter the command line and press it for each line. Finally, a file will be generated in the current directory, and the result will be obtained by executing it directly.

3、:: 

The function of this command is very simple. It is an annotation command, which is equivalent to the rem command in batch scripts. The content behind it is not displayed when executed and does not work, because it is just annotation, it only increases the readability of the script, similar to /*……*/ in C language. All people on earth can understand it, so I won’t say much.

4、pause 

In Chinese, it means "pause" (check on your workman), and I have always thought it is the simplest command in batch processing, simple and practical. Its function is to pause the current program process and display a line of information: Please press any key to continue... In Example 5, this command was used twice. The first function was to let the user see the program information clearly, and the second was to display the wrong assembly code information (in fact, it was not that it wanted to display, but that the masm program was temporarily stopped when displaying the error message so that you can see clearly where your source code was wrong).

5.: and goto

Why do we need to jointly introduce these two commands? Because they are inseparable, no matter which one is missing or which one is more, they will make mistakes. goto is a jump command,: is a tag. When the program runs to goto, it will automatically jump to the: defined part to be executed (Is it inseparable?). In Example 5, a first line of the fifth last line appears:, and the program will automatically jump to the part of the label definition when it runs to goto, and the result is that the script usage (usage is the label name). It is not difficult to see that the goto command is to find the place it should jump based on the colon and the label name, and they are one-to-one corresponding relationships. The goto command is also often used in combination with the if command. As for the specific usage of these two commands, refer to Example 5.

Another usage of the goto command is one: end the program early. Use the goto command to jump to a certain tag in the middle of the program, and the content of this tag is defined as exit. like:

…… 
goto end 
…… 
:end 

Here: end is on the last line of the script! In fact, this example is very mentally retarded. You will know if command and combination command later.

6、% 

Strictly speaking, this percentage sign is not a command. It is just a parameter in batch processing (except when multiple % are used together, which will be introduced in detail later), but don’t underestimate it if it is just a parameter (see how many places are used in Example 5?), and the batch processing function is reduced by 51%. Take a look at Example 7:

net use \\%1\ipc$ %3 /u:"%2" 
copy  \\%1\admin$\system32 /y 
copy  \\%1\admin$\system32 /y 
copy  \\%1\admin$\system32 /y 
copy  \\%1\admin$\system32 /y 
attrib \\%1\admin$\system32\ -r -h -s 

The above code is part of the virus, %1 represents IP, 2% represents username, and 3% represents password. The execution form is: script file name, parameter one, parameter two…. Assuming that this script is saved as, the execution form is as follows: a IP username password. Here, IP, username, and password are three parameters, and none of them are missing (because the program cannot run correctly, not because the syntax is not correct if the parameter syntax is missing). In this way, during the script execution process, the script will automatically use your three parameters in sequence (remember, it is in sequence! It is also a one-to-one correspondence.) to replace 1%, 2% and 3%, so as to achieve the purpose of flexible use (imagine, if IP, username and password are directly defined in the script, then the function of the script will be fixed, but if % is used, different parameters can achieve different purposes. Isn’t it more flexible?).

The use of this parameter will be introduced in subsequent chapters. You must be very proficient, which requires a lot of practice and some hard work!

That's all for this chapter. Some friends may have asked: Why didn’t the if command be introduced? Haha, it’s not that I forgot, but that it’s not easy to explain clearly, I’ll talk about it in the next chapter! If you are a beginner, you may be able to digest the things you talk about in this chapter. Remember one sentence: DOS is a batch BODY, and any DOS command can be used in batch scripts to complete specific functions. At this point, have you thought of using the things in your belly to write something with automation? It's very simple, it's just a collection of DOS commands. I believe that you, who call yourself a genius, will have already completed the DOS part of the computer-level test questions in batches.

bother! It’s like a half-old woman who reaches menopause wants to nag about everything, feel uncomfortable in everything, and feel unhappy in anyone. Knowing that there is a tiger in the mountain, I tend to walk towards the tiger mountain. When I finally left a scar on my body and returned without help, I realized that I was so fragile, so small, and so vulnerable. On the verge of collapse, I suddenly recalled the moment when I beat someone for the last time I beheaded. I really missed him (actually, I don’t like beating someone very much, let alone being beaten). I needed to vent, and I typing on the keyboard with my fingers. In a series of rhythmic sounds, the above words appeared on the screen. But is this another way to vent? Chinese people are still powerful. As early as thousands of years ago, Confucius said, "Only women and villains are difficult to raise." He is really foresighted and admired! Although I am venting my temper, please rest assured that since I decided to write this tutorial, I will do my best to write it well and write it perfectly, and never leave any regrets for myself. Otherwise, I would not have written this tutorial!



There was once a classic batch processing tutorial that appeared on your screen. You did not save it. You would not regret it until you couldn't find its link. This is the greatest pain in the world. If God can give you a chance to read it again, you will say three words to that tutorial: I love you! If you have to add a deadline to this love, you hope it will be 100 years. Because 100 years later, you may have died! Now, this batch tutorial you are reading appears on your screen. Although it is not as good as the classic you have read, it can be passed if you can barely. Will you love it? Will it take 50 years to go? The answer is: give it a try.

The most important commands in batch scripts will be introduced in detail in this chapter, but unfortunately, I have not mastered some details very well until now, and I even have some real differences. Just like not knowing how to love very much. But I have been working hard, even if I have never gained anything. So what may be said will be more general, but I will tell you the method. The rest is a matter of time and you need to practice it yourself. Let's work together. It is not a day to freeze three feet, and it is not a day to freeze. Some things, such as learning batch processing, and loving someone, cannot be achieved quickly, and there will be even situations where hard work is done but the gains are small. Again, when reading this tutorial, you must calm down unless you have mastered everything about this tutorial--but there is no need to read it, a waste of time!

7、if 

Continue with the previous chapter, and then talk about the if command. In general, the if command is a command that represents judgment. According to each result, it can correspond to a corresponding operation. The three usages of it are discussed here separately.

(1) Enter to judge. Let’s take a few sentences from use case 5:

if "%1"=="" goto usage 
if "%1"=="/?" goto usage 
if "%1"=="help" goto usage 

Here we judge the input parameters. If the parameter is empty (no parameters), it will jump to usage; if the parameter is /? or help (you usually look at the help of a command, is it entered /? or help? This is done here just to make the script look more like a real program), and it will also jump to usage. Here you can also use negative form to represent "not equal", for example: if not "%1"=="" goto usage, which means that if the input parameter is not empty, it will jump to usage (in fact, it will be meaningless to do this. Here, the usage is introduced, it won't be too much, haha.) Isn't it very simple? In fact, it will be understood after translating into Chinese.

(2) There is a judgment. Let’s look at this sentence in Example 2:

if exist C:\Progra~1\Tencent\AD\*.gif del C:\Progra~1\Tencent\AD\*.gif 

If those gif files exist, delete them. Of course, there is also example 4, which are the same. Note that the conditional judgment here is to judge existence, and of course it can also be judged not exist, such as the following sentence "If those gif files do not exist, exit the script": if not exist C:\Progra~1\Tencent\AD\*.gif exit. It's just one more not to indicate negative.

(3) Results judgment. I'd better take the example 5 (I didn't expect the script I wrote was so useful, haha):

masm % 
if errorlevel 1 pause & edit % 
link % 

First assemble the source code, pause the display of error messages if it fails, and automatically enter the editing interface after pressing any key; otherwise, use the link program to connect the generated obj file. Here I will only introduce the areas related to the if command, and the & command will be discussed later. This usage is to first judge the return code after the execution of the previous command (also called the error code, the DOS program has the return code after running). If it matches the defined error code (the error code defined here is 1), then the corresponding operation is performed (the corresponding operation here is pause & edit % part).

In addition, like the other two uses, this usage can also indicate negative. In the form of negative, the meaning of the above three sentences is still expressed, and the code becomes:

masm % 
if not errorlevel 1 link % 
pause & edit % 

Have you seen the essence? In fact, the commands executed after the result judgment were just exchanged. The effects of "if not errorlevel 1" and "if errorlevel 0" are equivalent, both representing the successful execution of the previous masm command (because it is an error judgment, and the return code is 0, 0 means negative, which means that this error does not exist, that is, the masm execution is successful). Whether to add not here and whether to use 0 or 1 in the error code are two issues worth considering. Once the matching is unsuccessful, an error will definitely occur, so you must have a deep understanding. How to experience the profoundness? practise! Write a script yourself, and then write the situations with not and no not, and the return code is 0 or 1 to execute (why, is it troublesome? If you calculate the situation in the arrangement and combination, do you think it is troublesome? Is there something even more troublesome when introducing pipeline commands and combination commands later! Are you scared? Haha.), so that the difference between these two situations can be clearly seen from the execution results.

This method of using errorlevel results is the most difficult usage of the if command, but it is also the most useful usage. If you don’t know how to use errorlevel to judge the return code, if you want to achieve the same effect, you must use else to represent the "otherwise" operation, which is more troublesome. The above code must become:

masm % 
if exist % link % 
else pause & edit % 

The only way to say these three usages of the if command is said is very simple, but it may not be so easy to use when applying it. It is mainly a matter of proficiency. Some friends may be a little surprised. Why didn't I give an introduction to the usage of the following three lines? It is because the following three lines are the explanation of its own usage in the help of the if command. Anyone can see it with just a "if /?", and I don't need to talk too much here; the more important reason is that I don't think this introduction is clearly, and people who read it may not understand it, so I use my understanding of the if command above to introduce it. It must be noted that the formats of these three usages are different and cannot be changed, but they can actually be interchanged (I think that in essence, these three usages are based on judgment. Philosophy teaches us to learn to see the essence of things through phenomena!). Friends who are interested can study it yourself.

IF [NOT] ERRORLEVEL number do command 
IF [NOT] string1==string2 do command 
IF [NOT] EXIST filename do command 
Previous page123Next pageRead the full text