set |
The set command manipulates environment variables from the command line.
TIP
Because the command prompt's environment is reset when its window is closed, the usefulness of set is fairly limited. To affect more permanent changes to environment variables, go to Control Panel System Advanced tab Environment variables. |
Type set without options to display all the current environment variables, or use this syntax:
set [ variable [=[ string ]]] set /p variable =[ promptstring ] set /a expression
Type set with only a variable name (no equal sign or value) to display a list of all the variables whose prefix matches the name . The set options are:
Option | Description |
---|---|
variable | Specifies the variable name. If variable is specified by itself, its value is displayed. If variable is specified by itself with an equals sign, the variable is assigned an empty value and deleted. variable cannot contain spaces. |
string | Specifies a series of characters to assign to variable . This can contain references to other variables by surrounding them with preceding and trailing percent signs ( % ). |
/p | Specifies that variable will be assigned by text input from the user , rather than string. |
promptstring | The text prompt to display when using the /p option. |
/a | Specifies that expression is a numerical expression to be evaluated. |
expression | When used with the /a option, expression is a collection of symbols, numbers , and variables arranged so that it can be evaluated by set. The following symbols are recognized (in decreasing order of precedence): () !~ */ +- << >> & ^ = *= /= %= += -= &= ^= = <<= >>= |
C:\> set dummy=not much C:\> set dircmd=/s /o-s C:\> set path=%path%;c:\mystuff C:\> set prompt=$t> C:\> set /p dummy=Enter text here> C:\> set /a 7+(3*4)
You can reference environment variables with other commands:
C:\> set workdir=C:\stuff\tim's draft C:\> cd %workdir%
Table 6-1 shows most of Windows ' predefined variables.
Variable | Description |
---|---|
ALLUSERSPROFILE | The location of the All Users folder, usually c:\Documents and Settings\All Users . |
APPDATA | The location of the Application Data folder, usually c:\Documents and Settings\%USERNAME%\Application Data . |
COMMONPROGRAMFILES | The location of the Common Files folder, usually c:\Program Files\Common Files . |
COMPUTERNAME | The network name of the computer, set by going to Control Panel System Computer Name tab Change. |
COMSPEC | The location of the command prompt application executable, c:\Windows\system32\cmd.exe by default. |
COPYCMD | Whether the copy, move, and xcopy commands should prompt for confirmation before overwriting a file. The default value is /-y. To stop the warning messages, set COPYCMD to /y. |
DIRCMD | Specifies the default options for the dir command. For example, setting DIRCMD to /p will cause dir to always pause after displaying a screenful of output. |
HOMEDRIVE | The drive letter of the drive containing the current user's home directory, usually c: , used with HOMEPATH. |
HOMEPATH | Along with HOMEDRIVE, the path of the current user's home directory, usually \Documents and Settings\%USERNAME% . |
LOGONSERVER | The name of the computer as seen by other computers on your network, usually the same as COMPUTERNAME preceded by two backslashes. |
OS | Used to identify the operating system to some applications; for Windows XP, OS is set to "Windows_NT." You may be able to "fool" an older program that is programmed not to run on an NT system by changing this variable temporarily. |
PATH | The sequence of directories in which the command interpreter will look for commands to be interpreted. See "path," earlier in this chapter. |
PATHEXT | The filename extensions (file types) Windows will look for in the directories listed in the path (see "path," earlier in this chapter). The default is .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH. |
PROGRAMFILES | The location of the Program Files folder, usually c:\Program Files . |
PROMPT | The format of the command-line prompt, usually $P$G. See "prompt," earlier in this chapter, for details. |
SESSIONNAME | The name of the current command prompt session; usually "Console." |
SYSTEMDRIVE | The drive letter of the drive containing Windows, usually c: . |
SYSTEMROOT | The location of the Windows directory (or more specifically , the name of the folder in which the \Windows\System32 folder can be found), usually c:\windows . |
TEMP and TMP | The location where many programs will store temporary files. TEMP and TMP are two different variables, but they should both have the same value. Usually set to C:\DOCUME~1\%USERNAME%\LOCALS~1\Temp (short name used to maintain compatibility with older DOS programs). |
USERDOMAIN | The name of the domain to which the computer belongs (set by going to Control Panel System Computer Name Change). If no domain is specified, USERDOMAIN is the same as COMPUTERNAME. |
USERNAME | The name of the current user. |
USERPROFILE | The location of the current user's home directory, which should be the same as HOMEDRIVE plus HOMEPATH, usually c:\Documents and Settings\%USERNAME% . |
WINDIR | The location of the Windows directory, usually c:\windows . |