Explained: Environmental variables

Explained: Environmental variables

Sometimes when you are looking for instructions to troubleshoot software issues or adapt software to your liking and you are looking at the knowledge base (KB) of said software, you will run into the use of environmental variables. Environmental variables are a Windows feature that describe certain important machine characteristics. These characteristics can be different for every machine, but they are very important when describing the path to certain files and folders. Not only can they vary from one machine to another, some are even different for other users of the same system.


Well-known examples of environmental variables are %COMPUTERNAME% and %USERNAME%. The notation – surrounded by percentage signs – tells you that an environmental variable is the object of the description. You can get a quick view of the variables that are preset on your system by using the following command in the command prompt: set.

This will result in a listing similar to this one:


Note that the variables themselves will be listed without the %% signs.“>

You can use Powershell to get a prettier version of the same list. The command to use is dir env: (see the header of this article for a part of that list).

Another way to access and change environmental variables is by visiting the Control Panel > System and Security > System screen. Select Advanced System Settings and on the Advanced tab, you should see a button labeled Environmental Variables… Click that button and you will see your environmental variables split out in User variables and System variables.


Here you can add, edit, and delete entries, but please be careful when doing so. Some of them are very much needed just the way they are and you can wreak havoc by making the wrong choices.

You may also notice that some programs you have installed add their own environmental variables to the “set-list”. We will focus on the standard Windows environmental variables as those are often used to locate certain files and folders. But in the KB articles we mentioned earlier, you may find that they use the environmental variables created by their own installer as well.

One way of testing what all these environmental variables mean is to paste or type them in a run command. Try it for example with %APPDATA%, which is an environmental variable that you will find in a lot of KB type of articles.


On a standard Windows 7 system, typing %APPDATA% takes you to the C:Users%USERNAME%AppDataRoaming folder location. This is exactly why environmental variables are useful: if the folder with that function is in a different location on your computer, it automatically takes you to that location. If you type %APPDATA% on a default Windows XP system, it opens C:Documents and Settings%USERNAME%Application Data folder location.

Of course, environmental variables are not only used to make KB articles more widely usable. They are also used in batch files and other programs. This saves system administrators a lot of work as he can use the same script for several computers, for example by utilizing the %COMPUTERNAME%  and %USERNAME% variables. Please note that %USERNAME% relates to the currently logged on user and not to other users of the same system.


This post is intended to make normal users aware of the existence and use of environmental variables, a Windows feature that is often only known to programmers and other advanced users.

Related links:


Pieter Arntz

Malware Intelligence Researcher

Was a Microsoft MVP in consumer security for 12 years running. Can speak four languages. Smells of rich mahogany and leather-bound books.