



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of environment variables in windows xp, their uses, and some common predefined and dynamic variables. Environment variables are placeholders for system properties and control the behavior of programs. Predefined variables include %allusersprofile%, %appdata%, %computername%, %comspec%, %homedrive%, %homepath%, %path%, %pathext%, %programfiles%, %prompt%, %systemdrive%, %systemroot%, %temp%, %username%, %userprofile%, and %windir%. Dynamic variables include %date%, %time%, %cd%, %errorlevel%, and %random%. The document also explains how to modify the path and pathext variables.
Typology: Exercises
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Environment variables have long been used in computer operating systems and are present in Unix, DOS, and Windows. The word "environment" used in the context here refers to various features of the computer system and certain basic system data. Here is one of Microsoft's definitions:
Environment variables are strings that contain information such as drive, path, or file name. They control the behavior of various programs. For example, the TEMP environment variable specifies the location in which programs place temporary files.
Values for some of these variables are established at login and these are sometimes called predefined variables. They include such parameters as the path and the name of the current user. A table of some of the more useful variables is given below. I have omitted some of the more technical ones. A more complete list is at this Microsoft reference. The variables are enclosed by percent signs when used in scripts or the command line, as is shown in the table. Although the variables are shown in upper case, they are not case- sensitive. More details are given about some of them in subsequent sections.
(To conform to much of the literature on environment variables, I will be using the term "directories" instead of "folders" in the discussion.)
Table I. Some more common predefined environment variables
Variable Typical value (May vary, depending on system)
%ALLUSERSPROFILE% C:\Documents and Settings\All Users
%APPDATA% C:\Documents and Settings\ {username} \Application Data
%COMPUTERNAME% {computername}
%COMSPEC% C:\Windows\System32\cmd.exe
%HOMEDRIVE% C:
%HOMEPATH% \Documents and Settings\ {username}
%PATH% C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem
%PATHEXT% .COM; .EXE; .BAT; .CMD; .VBS; .VBE; .JS ; .WSF; .WSH
%PROGRAMFILES% Directory containing program files, usually C:\Program Files
%PROMPT% Code for current command prompt format. Code is usually $P$G
%SYSTEMDRIVE% The drive containing the Windows XP root directory, usually C:
%SYSTEMROOT% The Windows XP root directory, usually C:\Windows
%TEMP% and %TMP% C:\DOCUME~1\ {username} \LOCALS~1\Temp
%USERNAME% {username}
%USERPROFILE% C:\Documents and Settings\ {username}
%WINDIR% C:\Windows
The so-called predefined variables are generally unchanged during a login session but there are also some dynamic variables whose value may change. Some of these are listed in the next table.
Table II. Some dynamic environment variables
Variable Value
%DATE% Current date in the format determined by the Date command
%TIME% Current time in the format determined by the Time command
%CD% Current directory with its full path
%ERRORLEVEL% Number defining exit status of a previous command or program
%RANDOM% Random number between 0 and 32767
Environment variables are very convenient in scripts where certain standard directories and parameters need to be referenced but where the actual locations or names can vary from computer to computer.(Note that the presence of spaces in some names may necessitate the use of enclosing quotation marks around environment variables in scripts.) By having a placeholder, no prior knowledge is required of such details as the exact location of Windows or who is logged in. Some possibilities are explored in the following sections.
The path to a file is basically its address on the computer. It tells programs how to find a file. It is the drive plus any directories and sub-directories where the file is located. The %PATH% environment variable specifies the command search path. Typically, this is a group of directories where executable files that are repeatedly used are to be found. Examples of the default values are listed in the first table above; in this case, they are the Windows directory and two of its important system sub-directories. To see what is in the PATH variable on a computer, open a command window and enter "echo %PATH%".
The PATH variable is not immutable and programs like Norton SystemWorks will stick themselves into PATH when they are installed. The PC user can also modify the contents using methods discussed further on. Adding directories to PATH can be very useful if you use scripts or the command line for system maintenance. For example, it can be convenient to put the directory where you keep backups into the PATH variable. It can also be useful to modify PATH if you put programs in a directory different from the usual one.
In the command line and in batch files, PATH can be modified by the command path = dir1;dir2;dir This command will create a PATH environment variable consisting of the three directories dir1 , dir2 , and dir3. Note that the directory names are separated by a semicolon in the command statement. (An alternate
the variables are on your system. Those who wish can consult this Microsoft article at (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/set.mspx ) for more details about "Set".
A more permanent way to manage environment variables is provided in the System Properties dialog box. Open Control Panel-Performance and Maintenance-System (or right-click on My Computer and choose "Properties"). In the box that opens, click the "Advanced" tab to obtain the dialog box shown below. Next, click the button "Environment Variables".
The figure below shows the "Environment Variables" dialog box that opens next. It lists two kinds of variable- those that apply only to the current user and those that apply to the whole system. You can simply scroll down the lists to see what is on your system or you can edit the lists. Note that I have created a user variable %BACKUP% that gives the path to my one of my backup directories. That makes it easier for me to write a backup script since all I have to do is enter %BACKUP% whenever I want to refer to this directory. To create a new variable, use the "New" button. There are also buttons for editing and for deleting variables.
The box for adding a new user variable is shown below. Generally, this is likely to be a directory that you use frequently but can be any string of less than 8192 bytes. The maximum total size for all environment variables, including variable names and the "equals" sign, is 32767 characters.
The next figure shows a box for editing a variable; in this case it is the PATH variable. Be sure to remember to separate directory names with a semicolon. If you use programs in a particular directory a great deal, you may wish to add it to the path. The figure shows that the directory "G:\Program Files\Support Tools" has been added.
To modify a System variable, you must be an administrator on the system. All users can modify their own User environment variables. In general, System variables will need a restart to become effective, while User variables will become effective immediately. Note however that after a change to the User environment variables is made, any open software programs should be restarted to force them to read the new registry values.