Working with Environment Variables

Windows XP Professional stores most of its configuration settings in the Windows XP registry. Some of this information is made available as system environment variables. Environmental variables are generated from information that is collected from a number of different sources, including:

  • HKEY_CURRENT_USER. User information collected during user login

  • HKEY_LOCAL_MACHINE. Hardware and software settings collected during system startup

There are two types of environment variables, user and system. User environment variables are user-specific, meaning that they may be set to different values for each user of the computer. System variables, on the other hand, affect the entire computer and every user of the computer. Changes made to environment variables are actually changes made to the Windows XP registry. Changes made to user environment variables are not effective until the user logs off and back on again. Changes to system variables are not effective until the computer is restarted.

Any changes made to environment variables are permanent, meaning that they survive across system restarts and remain in effect until changed or deleted.

Users can modify their own user variables. Only administrators can modify system variables.

Access to user and system variables is provided from the System Properties dialog. The following procedure outlines the steps involved in displaying these variables.

  1. Click on Start, right-click on My Computer, and select Properties. The System Properties dialog appears.

  2. Select the Advanced property sheet.

  3. Click on Environment Variables. The Environment Variables dialog appears, as shown in Figure 12.19.

    click to expand
    Figure 12.19: Displaying user and system variables

  4. The top portion of the dialog displays user variables. The bottom portion of the dialog displays system variables.

By default, two user environment variables are established for every user.These are:

  • TEMP. Specifies the location of a temporary folder where temporary files can be written during the user's login session

  • TMP. Specifies another location where temporary files can be stored

A number of system variables are automatically established and affect every user of the computer. These system variables include:

  • ComSpec. Identifies the location of the Windows shell

  • NUMBER_OF_PROCESSORS. Displays a value of 1 for single processor computers

  • OS. Displays the operating system's name

  • Path. Specifies the current search path

  • PATHEXT. Specifies a list of extensions that identify executable files

  • PROCESSOR_ARCHITECTURE. Identifies the computer's processor type

  • PROCESSOR_IDENTIFIER. Displays a detailed description of the computer's processor

  • PROCESSOR_LEVEL. Displays the processor's stepping level

  • PROCESSOR_REVISION. Displays the processor's revision number

  • TEMP. Specifies the location where temporary files can be stored

  • TMP. Specifies an alternative location where temporary files can be stored

  • windir. Identifies the location of the Windows folder

The following procedure outlines the steps involved in modifying an environment variable.

  1. Open the Advanced property sheet on the System Properties dialog and click on Environment Variables. The Environment Variables dialog appears.

  2. To modify a user or system variable, select the variable and click on the Edit button in the user or system variable section, depending on the type of variable selected.

  3. The Edit User Variable or Edit System Variable dialog appears.

  4. To change the variable's name, type a new name in the Variable name field.

  5. To change the value assigned to a variable, type a new value in the Variable value field.

  6. Click on OK.

  7. Click on OK twice to close the Environment Variables and System Properties dialogs.

Log off and back on again in order for a change to a user variable to take affect. For a change to a system variable to take effect, the computer must be restarted.

The following procedure outlines the steps involved in creating a new environment variable.

  1. Open the Advanced property sheet on the System Properties dialog and click on Environment Variables. The Environment Variables dialog appears.

  2. To create a new user or system variable, click on the New button in either the user or system section.

  3. The New User Variable or New System Variable dialog appears.

  4. Type the name of the new variable in the Variable name field.

  5. Type the value to be assigned to the new variable in the Variable value field.

  6. Click on OK.

  7. Click on OK twice to close the Environment Variables and System Properties dialogs.

The new environment variable will appear in the list of user or system variables but is not effective until the next login session or a restart is performed.

Deletion of environment variables should be performed with great care. No confirmation is required when deleting an environment variable, and the effect of removing it will not be known until the user's next login session or the next time the computer is restarted. The following procedure outlines the steps involved in deleting an environment variable.

  1. Open the Advanced property sheet on the System Properties dialog and click on Environment Variables. The Environment Variables dialog appears.

  2. To delete a user or system variable, select the variable and click on the Delete button in the user or system variable section, depending on the type of variable selected.

  3. Click on OK.

  4. Click on OK twice to close the Environment Variables and System Properties dialogs.

Not every variable is visible from the Environment Variables dialog. By executing the SET command at the Windows XP command prompt, additional variables can be displayed. For example, Figure 12.20 shows a typical list of variables displayed from the command prompt.

click to expand
Figure 12.20: Displaying variables from the Windows XP Professional command prompt

The SET command is especially important to administrators who develop Windows scripts because it allows scripts to create temporary variables that can be referenced throughout the script.

Note 

More information on Windows scripting and the use of the SET command is available in Chapter 14, "Shell Scripting and the WSH."



Microsoft Windows XP Professional Administrator's Guide
Microsoft Windows XP Professional Administrators Guide
ISBN: 1931841969
EAN: 2147483647
Year: 2005
Pages: 358

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net