Академический Документы
Профессиональный Документы
Культура Документы
Formatting legend
Format
Italic
Bold
Ellipsis (...)
Between brackets ([])
Between braces ({}); choices separated by
pipe (|). Example: {even|odd}
Courier font
Meaning
Information that the user must supply
Elements that the user must type exactly
as shown
Parameter that can be repeated several
times in a command line
Optional items
Set of choices from which the user must
choose only one
Code or program output
Character
Syntax
& [...]
Command1 &Command2
&& [...]
Command1 &&Command2
|| [...]
Command1 || Command2
Definition
Use to separate multiple commands on
one command line. Cmd.exe runs the
first command, and then the second
command.
Use to run the command following &&
only if the command preceding the
symbol is successful. Cmd.exe runs the
first command, and then runs the second
command only if the first command
completed successfully.
Use to run the command following ||
only if the command preceding || fails.
Cmd.exe runs the first command, and
then runs the second command only if
the first command did not complete
successfully (receives an error code
greater than zero).
( ) [...]
; or ,
Notes
The ampersand (&), pipe (|), and parentheses ( ) are special characters that must
be preceded by the escape character (^) or quotation marks when you pass them
as arguments.
the command-shell environment or the entire operating system environment by using two
types of environment variables, system and local. System environment variables define
the behavior of the global operating system environment. Local environment variables
define the behavior of the environment of the current instance of Cmd.exe.
System environment variables are preset in the operating system and available to all
Windows server operating system processes. Only users with administrative credentials
can change system variables. These variables are most commonly used in logon scripts.
Local environment variables are only available when the user for whom they were
created is logged on to the computer. Local variables set in the
HKEY_CURRENT_USERhive are valid only for the current user, but define the
behavior of the global operating system environment.
The following list describes the various types of variables in descending order of
precedence:
1. Built-in system variables
2. System variables found in the HKEY_LOCAL_MACHINE hive
3. Local variables found in the HKEY_CURRENT_USER hive
4. All environment variables and paths set in the Autoexec.bat file
5. All environment variables and paths set in a logon script (if present)
6. Variables used interactively in a script or batch file
In the command shell, each instance of Cmd.exe inherits the environment of its parent
application. Therefore, you can change the variables in the new Cmd.exe environment
without affecting the environment of the parent application.
The following table lists the system and local environment variables for the Windows
server operating system.
Variable
Type
%ALLUSERSPROFILE%
Local
%APPDATA%
Local
%CD%
Local
%CMDCMDLINE%
Local
Description
Returns the location of the All Users
Profile.
Returns the location where applications
store data by default.
Returns the current directory string.
Returns the exact command line used to
start the current Cmd.exe.
%CMDEXTVERSION%
System
%COMPUTERNAME%
System
%COMSPEC%
System
%DATE%
System
%ERRORLEVEL%
System
%HOMEDRIVE%
System
%HOMEPATH%
System
%HOMESHARE%
System
%LOGONSERVER%
Local
%NUMBER_OF_PROCESSORS%
System
%OS%
System
%PATH%
System
%PATHEXT%
System
%PROCESSOR_ARCHITECTURE% System
%PROCESSOR_IDENTFIER%
System
%PROCESSOR_LEVEL%
System
%PROCESSOR_REVISION%
System
%PROMPT%
Local
%RANDOM%
System
%SYSTEMDRIVE%
System
%SYSTEMROOT%
System
System
and
User
%TIME%
System
%USERDOMAIN%
Local
%USERNAME%
Local
%USERPROFILE%
Local
%WINDIR%
System
set VariableName
To add a variable, at a command prompt, type:
setVariableName=Value
To delete a variable, at a command prompt, type:
set VariableName =
You can use most characters as variable values, including white space. If you use the
special characters <, >, |, &, or ^, you must precede them with the escape character (^) or
quotation marks. If you use quotation marks, they are included as part of the value
because everything following the equal sign is taken as the value. Consider the following
examples:
Variable names are not case-sensitive. However, set displays the variable exactly as you
typed it. You can combine uppercase and lowercase letters in your variable names to
make your code more readable (for example, UserName).
Notes
The maximum total environment variable size for all variables, which includes
variable names and the equal sign, is 65,536KB.
you ensure that Cmd.exe references the variable values instead of making a literal
comparison. After you define variable values for a variable name, enclose the variable
name in percent signs. Cmd.exe searches for all instances of the variable name and
replaces it with the defined variable value. For example, if you create a script that
contains different values (for example, user names) and you want to define the
USERNAME environment variable for each user with these values, you can write one
script using the variable USERNAME enclosed in percent signs. When you run this
script, Cmd.exe replaces %USERNAME% with the variable values, which eliminates the
need to perform this task manually for each user. Variable substitution is not recursive.
Cmd.exe checks variables once. For more information about variable substitution, see For
and Call.