Windows Environment Variables

Environment variables are specially named "placeholders" used for both programming and in system administration.

Environment variables contain information such as a drive, path, or file name. For example, the TEMP environment variable specifies the location in which programs place temporary files. Environment Variables have been in use not only in Windows, but in Unix and DOS as well.

So how do these variables help you? Well, 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. For instance, on a Windows XP system, the TEMP folder is in C:\Windows\Temp whereas in Windows 2000 it is in C:\WINNT\Temp.

By having a placeholder, no prior knowledge is required of such details as the exact location or who is logged in All Environment Variables are enclosed in percentage (%) to mark them to the system as variables.

we has listed these variables below (a complete list is on the Microsoft site), and even cooler, how to make your own variables!



--------------------------------------------------------------------------------
Variable Typical value
%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
%SYSTEMDRIVE% The drive containing the Windows XP root directory, usually C:
%PROGRAMFILES% Directory containing program files, usually C:\Program Files
%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
%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


Environment Variables are found in your registry at:
User: HKEY_CURRENT_USER\Environment
System: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment



In a command window, any of the values of an environment variable can be given to you via the command: echo variable e.g. echo %PATH%



Adding, Editing and Removing Environment Variables in Windows
Adding variables to Windows or modifying existing ones is managed through the "Environment Variables" button on the Advanced Tab of System Properties. This feature has been available since the days of Windows NT, and specifically from Windows 2000 and XP you get to it via: Control Panel -> SYSTEM -> Advanced Tab
In Windows 7 and Windows Vista it is in: Control Panel -> System & Security -> System ->Advanced System Settings

For temporary changes, the command " Set" can be used in scripts or in a command window, avoiding the need to do something permanent if you are just executing a one-off operation perhaps. For example: set GAMES=C:\Games

To create a new variable, use the "New" button. There are also buttons for editing and for deleting variables. I have created a new variable under my User Properties called "Games" and specified where that directory exists in C:\Games. If you want a variable to apply to all users of the computer, enter them under System Variables. See below:

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


To add directories to the PATH variable, type:
PATH = %PATH%;newdir

Note, the method above adds the directory to the existing PATH variable's list. If you would like to replace all of the path variables with what you specify, enter: PATH = dir1;dir2;dir3

0 Response to "Windows Environment Variables"

Post a Comment