Friday, July 3, 2009

Environment Variables in Vista

From: http://vistaonwindows.com/environment_variables.html

I have discussed environment variables in some detail for Windows XP on another page. Many of the general considerations given there apply to Vista as well and they will not be repeated here. However, there are some changes and they will be outlined.

List of common preset environment variables

The table below lists the environment variables most usually encountered. I have omitted some of the more technical ones, such as those that give information about the CPU. Many of the variables in Vista are similar to those in Windows XP but there are some that are new. Also the paths associated with many have changed. Changes and additions are indicated.in red.

Table I. Some more common predefined environment variables in Vista
Variable Typical value (May vary, depending on system)
%ALLUSERSPROFILE% C:\ProgramData
%APPDATA% C:\Users\(username}\AppData\Roaming
%CommonProgramFiles%C:\Program Files\Common Files
%COMPUTERNAME% {computername}
%COMSPEC% C:\Windows\System32\cmd.exe
%HOMEDRIVE% C:
%HOMEPATH% \Users\{username}
%LOCALAPPDATA%C:\Users\{username}\AppData\Local
%PATH% C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem
%PATHEXT% .COM; .EXE; .BAT; .CMD; .VBS; .VBE; .JS ; .WSF; .WSH; .MSC
%ProgramData% C:\ProgramData
%PROGRAMFILES% Directory containing program files, usually C:\Program Files
%PROMPT% Code for current command prompt format. Code is usually $P$G
%Public% C:\Users\Public
%SYSTEMDRIVE% The drive containing the Windows XP root directory, usually C:
%SYSTEMROOT% The Windows XP root directory, usually C:\Windows
%TEMP% and %TMP% C:\Users\{Username}\AppData\Local\Temp
%USERNAME% {username}
%USERPROFILE% C:\Users\{username}
%WINDIR% C:\Windows

Vista has changed the locations for many of the personal files and settings. For example, there is no longer a "Documents and Settings" folder. Most of the XP environment variables that referred to this folder are still in Vista but involve the new "Users" folder. (As an aside: why does Microsoft continue to use some folders whose names have spaces like "Program Files"? It means that environment variables often have to be put in quotation marks.) There are also four new environment variables listed in Table I. These are %CommonProgramFiles%, %LocalAppdata%, %ProgramData%, and %Public%

Dynamic environment variables

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. These are the same as in Windows XP but are listed again for convenience.

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

Editing and addding environment variables

Sometimes it is desirable to edit certain of the environment variables such as %PATH%. Or it may be useful to create a user-defined environment variable. Vista contains a command-line method SETX that provides a variety of options. It can be used to either create or modify environment variables. Variables can be in the user or the system environment. The command has a number of switches that make it useful in scripts. (Needs administrator privileges.)

Environment variables can also be edited directly in the Registry. They are stored in the same Registry keys as they are in Windows XP. System variables are in the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment User-specific variables are in HKEY_CURRENT_USER\Environment

No comments:

Post a Comment

Popular Posts