set
The set
command manipulates environment variables
from the command line.
Type set
without options to display all the
current environment variables, or use this syntax:
set [variable
[=[string
]]] set /pvariable
=[promptstring
] set /aexpression
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:
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 im's draft
C:>cd %workdir%
Table 6-1 shows most of Windows' predefined variables.
Table 6-1. Predefined Windows variables
Variable |
Description |
---|---|
ALLUSERSPROFILE |
The location of the All Users folder, usually c:Documents and SettingsAll 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 FilesCommon 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:Windowssystem32cmd.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 WindowsSystem32 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~1Temp (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. |