Taking Control of System Properties, Startup, and Shutdown - 6.15 Creating Environment Variables
(Page 3 of 6 )
Problem
You want to be able to add environment variables to XP, so that scripts and certain programs can operate properly.
Solution
Using a graphical user interface
- Log in as an administrator (only system administrators can set environment variables).
- Right-click My Computer and choose Properties.
- Click the Advanced tab and click Environment variables. The environment variables dialog box, shown in Figure 6-11, appears.

Figure 6-11. The Environment Variables dialog box lets you see what variable are already set, edit them, delete them, and add new ones
- To add a new value, click New in the User variables or System variables area, depending on whether you’re adding variables for all users of the system or just the logged-on user.
- In the New User Variable dialog box that appears, type the name for the variable in the Variable name box, and the value for the variable in the Variable value box, for example, TMP for the variable name, and %USERPROFILE%\LocalSettings\Temp.
- Click OK until all boxes close.
- To edit a value, highlight it, click Edit, change the variable name and value, and click OK until all boxes close. To delete a value, highlight it, click Delete, then click OK until all boxes close.
- Usually, changes to values require that you restart your PC, so restart to make sure that the changes take effect.
Using a command-line interface
At the command prompt, use this syntax to set an environment variable:
> set variablename=variablevalue
For example, to set the variableProgramFilescto the valueC:\Program Files, you’d type this at a command prompt and press Enter:
> set variablename=variablevalue
That will set the environment variable only temporarily, and only in the command prompt; it won’t affect the rest of the system. To set permanent environment variables, use the GUI as detailed in the earlier part of this recipe.
Discussion
Environment variables that contain information about the environment for the system and/or for the currently logged on user are used for a wide variety of purposes—for example, to determine where to place files such as temporary files, what the root drive is, and where the Windows directory is. They’re often used in scripting as well. Windows contains a variety of environment variables by default, such as defining the root directory and the Windows directory.
If you’re at the command prompt and want to see the current environment variables, typeset and press Enter. You’ll see a list like this:
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;. JS;. JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 1 Stepping 2, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=0102
ProgramFiles=C:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\PRESTO~1\LOCALS~1\Temp
TMP=C:\DOCUME~1\PRESTO~1\LOCALS~1\Temp
USERDOMAIN=PRESTONGRALLA
USERNAME=Preston Gralla
USERPROFILE=C:\Documents and Settings\Preston Gralla
windir=C:\WINDOWS
Greating Environment Variables
See Also
MS KB 310519, “How To Manage Environment Variables in Windows XP”
Next: 6.16 Creating a Reboot or Shutdown Shortcut >>
More Windows Scripting Articles
More By O'Reilly Media
|
This article is excerpted from chapter six of the Windows XP Cookbook, written by Robbie Allen and Preston Gralla (O'Reilly; ISBN: 0596007256). Check it out today at your favorite bookstore. Buy this book now.
|
|