Package you learn to batch organize set page 1 / 3


The purpose of writing this tutorial is to let everyone who has read these words remember one sentence: if love can make things easier, let it be! The way to see this tutorial is slow! Slowly, like tasting a woman or a cup of tea, you will find that many things that were in front of you before suddenly become very far away, while some things that are very far away suddenly come back to you. ..

Let’s give an overview of the first batch processing. So far, I haven’t been able to give a suitable definition of batch processing – many experts haven’t given it either – anyway, I don’t know – I’m not necessarily convinced after reading it – I’m a rookie, of course, not to mention it; but I want to summarize a “more suitable” one, and I believe I can explain it clearly, so that more rookies can know what it is What can you do with this Dongdong. Maybe you will “unconditionally fall in love with batch processing” because of this article, then my goal is achieved – I just want you to fall in love with it, I just drag it, what can you do?? Really, love sometimes so drag, is so no reason, is so shameless! Really?

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

OK, never claver and get to business. Batch, also known as batch script, English translation for batch, batch file suffix bat take the first three letters. There is no fixed format for its composition, as long as it follows: each line can be regarded as a command, and each command can contain multiple subcommands, which are executed from the first line to the end of the last line. It runs on DOS platform. Batch processing has a very distinct feature: easy to use, flexible, powerful, high degree of automation. I don’t want to make my own tutorial boring, because it involves code The problem is boring, few people can face the full screen code and calm down. So I will use a lot of simple and practical examples to let my friends who read this tutorial experience the glamour of batch processing, feel its ancient spirit and strange character, and unconsciously fall in love with batch processing? What does batch processing have to do with love? Answer: no. Another “gossip”: to learn batch processing well, DOS foundation must be firm! Of course, brain flexibility is also a very important aspect.

Example 1: first, give a batch script that is the most easy for you to get familiar with. Save the following lines of commands as name.bat Then execute (only the code will be given later, and the way of saving and executing is similar)

ping > a.txt 
ping >> a.txt 
ping >> a.txt 
ping >> a.txt 
ping >> a.txt 
ping >> a.txt 
ping >> a.txt 
ping >> a.txt 

Can you understand everything? Is it easy? But its function is very practical. After executing this batch processing, you can create a file named a.txt in your current disk. The information recorded in it can help you quickly find the fastest QQ server, so as to stay away from the painful process of “transferring from the server”. Here, the meaning of > is to put the things obtained by the previous command in the place given later. The function of > > is the same as that of > except that the result is appended to the result obtained by the previous line, specifically the next line, while the result obtained by the previous line will be retained. This can make the a.txt file larger and larger (think of how to destroy it?). By the way, this batch processing can also be combined with other commands to make it a completely automatic way to judge the speed of the server, and directly display the fastest server IP after execution. Isn’t that cool? It will be described in detail later.

Second, give another out of date example (a.bat)

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

Why is this an outdated example? It’s very simple, because now almost no one uses QQ with ads (Kao, my QQ also shows friends around it!) So it’s almost useless. But once its role is not to be underestimated: delete QQ ads, let the dialog clean. The address used here is the default installation address of QQ. The default batch file name is a.bat. Of course, you can modify it according to the situation. In this script, the if command is used to make it timely judge and delete advertising pictures. You just need not close the DOS window after the command is executed, and do not press Ctrl + C to forcibly terminate the command. It will always monitor whether there are advertising pictures (QQ will also constantly check whether its own ads are deleted). Of course, this script takes up a little bit of your memory, ha ha
Learn batch processing! Really want to learn very easy!

Example 3: use the batch script to check if there is ice. The script 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. As long as you know the ports used by common Trojans, you can easily judge whether they have been frozen. However, this is not certain, because the default port 7626 of glacier can be completely modified. Here is just the method and thinking. Here is the method and idea. With a little change, it will become a script that can check other Trojans. With another change, after adding parameters, ports and information list files, it will become a script that can automatically detect all Trojans. Ha ha, isn’t it very enjoyable? The script also uses the combined Command & and pipeline command |, which will be described in detail later.

Example 4: 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 Every time the system starts up, the system garbage will be automatically deleted. Here we need to pay attention to two points: first, DOS does not support long file names, so tempor ~ 1 appears; second, we can change it according to our own actual situation to make it meet our own requirements.

The following is the online use of more cleaning system garbage bat

@echo off 
Echo is cleaning up system junk files, please wait 
del /f /s /q %systemdrive%\*.tmp 
del /f /s /q %systemdrive%\*._mp 
del /f /s /q %systemdrive%\*.log 
del /f /s /q %systemdrive%\*.gid 
del /f /s /q %systemdrive%\*.chk 
del /f /s /q %systemdrive%\*.old 
del /f /s /q %systemdrive%\recycled\*.* 
del /f /s /q %windir%\*.bak 
del /f /s /q %windir%\prefetch\*.* 
rd /s /q %windir%\temp & md %windir%\temp 
del /f /q %userprofile%\cookies\*.* 
del /f /q %userprofile%\recent\*.* 
del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\*.*" 
del /f /s /q "%userprofile%\Local Settings\Temp\*.*" 
del /f /s /q "%userprofile%\recent\*.*" 
Echo cleaning system garbage complete!

Well, see here, are you interested in batch scripts? Do you find that you have gradually fallen in love with this Dongdong? Don’t be happy too early, love is not a simple thing, it may bring you happiness and happiness, of course, can also make you want to jump. If you know it’s hard to continue, I’ve convinced you! Keep working hard, maybe you don’t get true love in the end (it’s really possible, everyone who has loved knows), but you can experience the whole process of love, that’s it. Sour, bitter and spicy, there is no sweet God knows.

Why is batch processing related to love? It’s not because I’m bored or because it’s interesting to write like this. There are two reasons: first, there are many similarities between batch processing and love. In some places, I can’t explain it clearly in the “professional” jargon (I don’t doubt my ability of expression, but it’s hard to explain it clearly in the matter itself), saying = not saying, but using the metaphor of love (what is love? How do I know Maybe you’ll get twice the result with half the effort. Why not? Second, I’m not in a good state during this period. I have a cold, fever, headache and stuffy nose, but it’s mainly emotional and mental devastation. I’m very tired of the people who do it. When I write the tutorial, I feel that everyone should buy dogskin plaster, and I can omit it completely (maybe it’s really effective – you won’t fall asleep and knock your head to come to me for reimbursement of medical expenses). Maybe in the next tutorial, you will see the heroes written by master Jin, such as Yang Guo and Zhang Wuji.

Friends who have read the first chapter must have a preliminary impression of batch processing and know what it is used for. But do you know the essence of batch processing? In fact, it is very simple: flexible thinking! There is nothing impossible, only 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. Nonsense!) And batch processing is a paradise for you, you can do whatever you want, there is no realm you can’t reach!

Batch processing seems disordered, but its logic is not lower than that of other programming languages (such as assembly). If you write a messy script, although every line of command is correct, you may not get the result you want from the beginning to the end. Maybe it is a bad command or fail name on a screen. This has something in common with love: step by step, the lack or increase of steps may lead to unwanted results. If you fall in love, I believe there is no doubt. My love batch processing, the output result is not bad command or fail name, the screen is like this: “your love” is not an internal or external command, nor a runnable program or batch file. Then the cursor keeps flashing, waiting for the next wrong input.

Starting from this chapter, we will introduce the common commands in batch processing from simple to deep. Many common DOS commands are widely used in batch script. They are the body part of batch script, but batch processing is more flexible and more automatic than DOS. To learn batch processing well, DOS must have a solid foundation. This article only talks about some DOS commands that are less used (relatively speaking), but not common commands such as copy and dir (these seemingly simple commands are actually very complex, I’m afraid I can’t explain them clearly!).

Let’s take a look at an example. This is a very interesting script, a small and practical good thing, the batch “automation” features embodied incisively and vividly. Let’s first introduce the origin of this script: we all know that the process of MASM is to assemble and connect the source code first, and then execute it. There are many links in this process that need to input a lot of things, which is very troublesome (only experienced friends can understand it). How to make this process easier? When we did the course design of assembly, I was “forced” to write this script, which was very cool to use, ha ha. Look at the script:

@echo off 
::close echo 
::clean screen 
echo This programme is to make the MASM programme automate 
::display info 
echo Edit by CODERED 
::display info 
echo Mailto me : qqkiller*** 
::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 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 
::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, calm down and look at it carefully (think back on the first paragraph of Chapter 1, how to write it)!). The explanation of each line of command has been given, and the content after the two colons is the e text of the previous line , which does not appear or work when the script is executed. There is a colon at the beginning of the penultimate line. It’s not a clerical error! The specific role will be discussed in detail later. In this script, MASM and link are assembler and linker, which must be combined with edit program and the source code you want to edit (of course, this script, nonsense!) Together in the current directory. Using this batch script, manual input can be reduced as much as possible. In the whole process, you only need to press the Enter key a few times to realize the automatic conversion from the assembly source code to the executable EXE file, and has the intelligent judgment function: if there is an error in the source code during the assembly (assembly is not successful), the error information will be automatically suspended, and the system will automatically enter after pressing any key Edit the source code interface; if the source code assembly is successful, connect and automatically execute the generated EXE file after connecting. In addition, due to the simplicity and flexibility of the batch command, this script also has good improvability, which can be easily modified to meet the computer habits of different friends. If you are learning assembly, don’t forget to practice!

Learn batch processing! How to learn (2)

In this script, the following commands appear: @, echo,::, pause,: and goto,%, and if. And this chapter will talk about these commands.


This symbol is not unfamiliar to everyone. It is a necessary symbol of email. How can it be used in batch processing? Hehe, it’s not its fault. Batch processing can’t do without it, or it’s not perfect. Its function is not to display the command itself in the execution window. Hehe, to be more popular, if you have it at the beginning of the line, the command of this line will not be displayed. In example 5, @ in the first line of @ echo off, the function of @ is to make the script not display the echo off section when it is executed. Do you understand? Still don’t understand? It doesn’t matter. After reading the brief introduction of echo command, you will understand naturally.


Chinese means “feedback” and “echo”. It is actually a switch command, that is to say, it has only two states: on and off. So there are two commands echo on and echo off. If echo command is executed directly, the current echo command status (off or on) will be displayed. If echo off is executed, the echo will be turned off. All commands after it will not display the command itself, but only display the result after execution, unless echo on is executed. In example 5, the @ command on the first line and the echo off command are combined to achieve two purposes: do not display the echo off command itself, and do not display the commands in the following lines. It’s really a bit messy, but if you practice it, you’ll get a refund in 3 minutes!

Another use of echo command one: you can use it to display information! For example, in the penultimate line of example 5, default bat file name is START.BAT It will be displayed in the window after the script is executed, but the echo command itself will not be displayed (why?).
Another use of echo command 2: you can edit the text file directly. Example 6:

echo nbtstat -A > a.bat 
echo nbtstat -A >> a.bat 
echo nbtstat -A >> a.bat 

The above script content can be edited directly from the command line with a carriage return per line. Finally, a file of a.bat will be generated in the current directory, and the result will be obtained by direct execution.


The function of this command is very simple. It is a comment command, which is equivalent to REM command in batch script. The content behind it is not displayed and does not play any role in execution, because it is just a comment, which only increases the readability of the script, and / *…, which is used in C language */Similar. People on earth can understand it, so I won’t say much.


“Pause” means “pause” in Chinese. I always think it is the simplest command in batch processing, simple and practical. Its function is to make the current program process pause, and display a line of information: please press any key to continue. In example 5, this command is used twice. The first one is to let the user see the program information clearly, and the second one is to display the wrong assembly code information (in fact, it is not intended to display, but the MASM program is temporarily stopped when it displays the error information, so that you can see where your source code is wrong).

123 read the full text on the next page

Recommended Today

Swift advanced 08: closure & capture principle

closure closurecanCapture and storageOf any constants and variables defined in their contextquote, this is the so-calledClose and wrap those constants and variablesTherefore, it is called“closure”Swift can handle everything for youCaptured memory managementOperation of. Three forms of closure [global function is a special closure]: a global function is a closure that has a name but does […]