Environment variables hold values related to the current environment, like the Operating System or user sessions.
Setting Environment variables via the GUI
- Open
Control Panel » System » Advanced » Environment Variables
. - Type
control sysdm.cpl,,3
in the Run dialog (+R) and clickEnvironment Variables
.
For editing user variables you can also type%windir%\System32\rundll32.exe sysdm.cpl,EditEnvironmentVariables
in the Run dialog. - Right-click (My) Computer and click on Properties, or simply press +Break.
- In XP click on
Advanced » Environment Variables
. - In Vista+ click on
Advanced system settings » Environment Variables
.
- In XP click on
- There are many other ways of reaching the same place, such as by typing "environment variables" in the Start Menu/Screen search box and so on.
Environment variables in Windows are separated into user and machine/system specific values. You can view and edit their values there. Their current values upon launch are made available to all programs.
Setting Environment variables via the Command Line
Format
Environment Variables in Windows are denoted with percent signs (%) surrounding the name:
%name%
echo
To display an environment variable's value in
cmd.exe
, type echo %name%
.C:\>echo %USERPROFILE%
C:\Users\Daniel
set
To create/set a variable, use
set varname=value
:C:\>set FunnyCatPictures=C:\Users\Daniel\Pictures\Funny Cat Pictures
C:\>set FunnyCatPicturesTwo=%USERPROFILE%\Pictures\Funny Cat Pictures 2
To append/add a variable, use
set varname=value;%varname%
:C:\>set Penguins=C:\Linux
C:\>set Penguins=C:\Windows;%Penguins%
C:\>echo %Penguins%
C:\Windows;C:\Linux
Environment variables set in this way are available for (the rest of) the duration of the Command Prompt process in which they are set, and are available to processes that are started after the variables were set.
setx
To create/set a variable permanently, use
setx varname "value"
:C:\>setx FunnyCatPictures "C:\Users\Daniel\Pictures\Funny Cat Pictures"
[Restart CMD]
C:\>echo %FunnyCatPictures%
C:\Users\Daniel\Pictures\Funny Cat Pictures
Unlike
set
, there is no equals sign and the value should be enclosed in quotes if it contains any spaces. Note that variables may expand to a string with spaces (e.g., %PATH%
becomes C:\Program Files
), so it is best to include quotes around values that contain any variables.List of Windows Environment Variables
Here is a list of default environment variables, which are built into Windows. Some examples are:
%WINDIR%
, %SystemRoot%
, %USERPROFILE%
, and %APPDATA%
. Like most names in Windows, these are case-insensitive.
No comments:
Post a Comment