Recipe 6.15. Creating Environment Variables


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

  1. Log in as an administrator (only system administrators can set environment variables).

  2. Right-click My Computer and choose Properties.

  3. 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


  4. 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.

  5. 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%\Local Settings\Temp.

  6. Click OK until all boxes close.

  7. 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.

  8. 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 variable ProgramFilesc to the value C:\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, type set 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

See Also

MS KB 310519, "How To Manage Environment Variables in Windows XP"



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

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