Batch files are non-formatted text files, and now diskless files are basically implemented by it, because the following is a simple and practical example to help you create batch files
Introduction to a simple batch processing internal command
1. Echo command
Enable or disable the request echo function or display messages. If no parameters exist, the echo command displays the current echo settings.
Syntax
Echo [{onoff}] [message]
Sample: @ echo off/echo hello world
In actual application, we will combine this command with the redirection symbol (also known as the pipeline symbol) to input some commands to a file in a specific format. this will be reflected in future examples.
2. @ command
The command after @ is not displayed. In the intrusion process (for example, you can use batch processing to format the enemy's hard disk), the other party cannot see the command you are using.
Sample: @ echo off
@ Echo Now initializing the program, please wait a minite...
@ Format X:/q/u/autoset (the/y parameter cannot be used for the format command. Fortunately, Microsoft has reserved the autoset parameter for us, the effect is the same as that of/y .)
3. Goto command
Specify to jump to the tag. After the tag is found, the program processes the commands starting from the next line.
Syntax: goto label (label is a parameter that specifies the rows in the batch processing program to be switched .)
Sample:
If {% 1 }={} goto noparms
If {% 2 }={} goto noparms (if you do not understand the if, % 1, and % 2 here, skip the step first, which will be explained in detail later .)
@ Rem check parameters if null show usage
: Noparms
Echo Usage: monitor. bat ServerIP PortNumber
Goto end
The name of a tag can start at will, but it is better to have a meaningful letter. Add a letter before it to indicate that the letter is a tag. The goto command is based on this: to find the next step and jump to it. It is better to have some explanations so that others seem to understand your intention.
4. Rem command
The annotation command is equivalent to/* -------- */in the C language. It is not executed, but serves as a comment for others to read and modify.
Rem Message
Sample: @ Rem Here is the description.
5. Pause command
When running the Pause command, the following message is displayed:
Press any key to continue...
Sample:
@ Echo off
: Begin
Copy a: *. * d: // back
Echo Please put a new disk into driver
Pause
Goto begin
In this example, all files on drive A are copied to drive d: // back. When the displayed note prompts you to put another disk into drive A, the pause command will suspend the program so that you can change the disk and press any key to continue processing.
6. Call Command
Call another batch processing program from one batch processing program without terminating the parent batch processing program. The call Command accepts the labels used as the call target. If a Call is used outside a script or batch file, it does not work in the command line.
Syntax
Call [[Drive:] [Path] FileName [BatchParameters] [: label [arguments]
Parameters
[Drive:} [Path] FileName
Specifies the location and name of the batch processing program to be called. The filename parameter must have the. bat or. cmd extension.
7. start command
Call an external program. All the DOS commands and command line programs can be called by the start command.
Common Intrusion parameters:
Minimum window size when MIN starts
SEPARATE starts a 16-bit Windows program in a SEPARATE space
HIGH starts applications in the HIGH priority category
REALTIME starts applications in the REALTIME priority category
WAIT starts the application and waits for it to end
Parameters: these are parameters sent to the command/program.
When the executed application is a 32-bit GUI application, CMD. EXE returns a command prompt before the application is terminated. If it is executed in the Command Script, the new behavior will not occur.
8. choice command
Choice uses this command to allow users to enter a single character to run different commands. The/c: parameter should be added for use, and c: should be followed by a prompt to enter characters without spaces. Its return code is 1234 ......
For example: choice/c: dimethyl defrag, mem, end
Will display
Defrag, mem, end [D, M, E]?
Sample:
The content of Sample. bat is as follows:
@ Echo off
Choice/c: dimethyl defrag, mem, end
If errorlevel 3 goto defrag (the highest error code should be determined first)
If errorlevel 2 goto mem
If errotlevel 1 goto end
: Defrag
C: // dos // defrag
Goto end
: Mem
Mem
Goto end
: End
Echo good bye
After this file is run, defrag, mem, end [D, M, E]? You can select d m e, and then the if statement will make a judgment. d indicates the program segment with the execution label as defrag, and m indicates the program segment with the execution label as mem, e indicates the program segment whose execution label is end. Each program segment finally jumps the program to the end label using goto end. Then, the program displays good bye, and the file ends.
9. If command
If indicates whether the specified conditions are met, and then different commands are executed. There are three formats:
1. if "parameter" = "string" command to be executed
If the parameter is equal to the specified string, the condition is true. Run the command. Otherwise, run the next sentence. (Note that there are two equal signs)
For example, if "% 1" = "a" format:
If {% 1 }={} goto noparms
If {% 2 }={} goto noparms
2. if exist file name command to be executed
If a specified file exists, the condition is true. Run the command. Otherwise, run the next sentence.
For example, if exist config. sys edit config. sys
3. if errorlevel/if not errorlevel number command to be executed
If the return code is equal to the specified number, the condition is true. Run the command. Otherwise, run the next sentence.
For example, if errorlevel 2 goto x2
When the DOS program runs, a number is returned to DOS, which is called the error level or return code. Common return codes are 0 and 1.
10. for command
The for command is a complex command. It is mainly used to execute commands cyclically within a specified range of parameters.
When using the FOR command in a batch file, use % variable to specify the variable
For {% variable} in (set) do command [CommandLineOptions]
% Variable specifies a single letter replaceable parameter.
(Set) specifies one or more files. Wildcard characters can be used.
Command specifies the command executed on each file.
Command-parameters specifies a parameter or command line switch for a specific command.
When using the FOR command in a batch file, use % variable to specify the variable
Instead of % variable. Variable names are case sensitive, so % I is different from % I
If the command extension is enabled, the following additional FOR command formats are subject