Set displays, sets, or deletes environment variables. If used without any parameters, the set command displays the current environment settings.
Syntax
set ] ] string]
Parameters
/a
Sets string to a numeric expression that can be evaluated.
/p
Sets the value of variable to a line of input.
variable
Specifies the variable to set or modify.
string
Specifies the string to associate with the specified variable.
/?
Displays help at the command prompt.
Remarks
Using set in the Recovery Console
The set command has different parameters when used from the Recovery Console.
Using special characters
The characters < > | & ^ are special command shell characters. When used in a string, they must be preceded by the escape character (^) or enclosed in quotation marks (that is, "StringContaining&Symbol"). If you use quotation marks to enclose a string containing special characters, those quotation marks become part of the environment variable value.
Using environment variables
Environment variables can be used to control the operation of certain batch files and programs, and can also control the way the Windows XP and MS-DOS subsystems display and work. The set command is often used in the Autoexec.nt file to set environment variables.
Displaying the current environment settings
If you type only the set command, the current environment settings are displayed. These settings usually include the COMSPEC and PATH environment variables, which help locate programs on the disk. Two other environment variables used by Windows XP are PROMPT and DIRCMD.
Using parameters
When you specify a variable and a string value, the specified variable value is added to the environment, and the string is associated with that variable. If the variable already exists in the environment, the new string value replaces the old string value.
If you specify only a variable and an equal sign for the set command (with no string), the string value associated with that variable is cleared (as if the variable did not exist at all).
Using /a
The following table lists the operators supported by /a in order of precedence from highest to lowest.
Operator Operation performed
< > Grouping
* / % + - Arithmetic
<< >> Logical shift
& Bitwise "and"
^ Bitwise "exclusive or"
| Bitwise "or"
= *= /= %= += -= &= ^= |= <<= >>= Assignment
, Expression separator
If you use logical (&& ||) or modulus (%) operators, enclose the expression string in quotation marks. Nonnumeric strings in expressions are treated as environment variable names, whose values are converted to numbers before processing. If an environment variable name is specified that is not defined in the current environment, a value of zero is assigned, allowing you to perform arithmetic with environment variables without having to use % to retrieve the value.
If you run set /a from the command line outside a command script, the final value of the expression is displayed.
Numeric values are decimal numbers. Prefixing with 0× indicates a hexadecimal number, and prefixing with 0 indicates an octal number. Therefore, 0×2 is the same as 18, and also the same as 022. Octal notation can easily cause confusion. For example, 08 and 09 are not valid numbers, because 8 and 9 are not valid octal digits.
Using /p
Requires a prompt string.
Supporting delayed environment variable expansion
Support for delayed environment variable expansion has been added. This support is disabled by default, but can be enabled or disabled with cmd /v.
Using command extensions
When command extensions are enabled (the default) and set is run by itself, all current environment variables are displayed. If you run set with a value, variables matching that value are displayed.
Using set in batch files
When creating a batch file, you can use the set command to create variables, and then use those variables the same way you use the numbered variables %0 through %9. You can also use the %0 through %9 variables as input to the set command.
Calling set variables from batch files.
When calling a variable value from a batch file, you must enclose the value in percent signs (%). For example, if a batch program creates an environment variable BAUD, you can type %baud% at the command line and use the string associated with BAUD as a replaceable parameter.
Examples
To set an environment variable named TEST^1, type:
set testVar=test^^1
To set an environment variable named TEST&1, type:
set testVar=test^&1
Set assigns the variable value to the content after the equal sign (=). If you type:
set testVar="test^1"
the result will be:
testVar="test^1"
To set an environment variable named INCLUDE so that the string C:\Inc( (the \Inc directory on drive C) is associated with that variable, type:
set include=c:\inc
You can then use the string C:\Inc in a batch file by enclosing INCLUDE in percent signs (%). For example, you might include the following command in a batch file to display the contents of the directory associated with the INCLUDE environment variable.
dir %include%
When this command is processed, the string C:\Inc replaces %include%.
You can also use set in a batch program to add a new directory to the PATH environment variable. For example:
@echo off
rem ADDPATH.BAT adds a new directory
rem to the path environment variable.
set path=%1;%path%
set
When command extensions are enabled (the default) and set is run with a value, variables matching that value are displayed. For example, if you type set p at the command prompt, the result will be:
Path=C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 8 Stepping 1, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0801
ProgramFiles=C:\Program Files
PROMPT=$P$G