As any good programmer or developer knows, writing code that references environment variables instead of hard coding paths will always keep them out of trouble. For the average home Computer user, using variables to reference applications and program executables or folders locations when creating shortcuts, writing scripts and in batch files is also a good idea.
But for many home Window users, variables may be something of an unknown, let alone where to find them, how to use them and how to create new variables.
So What Are Environment Variables?
Environment variables are specially named aliases that are placeholders for certain basic system properties. Environment variables are strings that contain information such as drive, path, or file name, which control the behavior of various programs.
How Do I See Environment Variables?
The easiest method is to click on Start \ Run, type sysdm.cpl and click OK.
In the System Properties dialog box, click the Advanced tab, then click on the Environment Variables button at the bottom.
Two types of variables exists, User, which is for the current account that is logged on and System. As you might expect, any variables listed for the User, can only be used by that account, while System is global and available to everyone.
In reality, there are more variables not shown above. To see them all, open a command prompt and type the command set.
Yea, But How Do They Work?
In the System variable section, scroll down to the temp variable. You will notice the value equals C:\Windows\TEMP. If you were creating a batch file and wanted to reference the path to the TEMP directory, instead of typing the full path, you can reference it as %TEMP%.
Now later, say you needed to move the location of the TEMP directory. You can then just change the value to the new path of the TEMP variable, and not worry about needing to find all the batch files if you had hard coded the path.
You are not limited to using the variables that currently exists. You can easily create new variables by clicking on the New button in the Environment variables dialog box (screen shot above).
In the example above, I created a variable called MP3 with the value of c:\mymusic\mp3. Now, when I create a shortcut to the mp3 folder, I would enter the path as just %MP3%. Later, I can move the mp3 folder anywhere and just change the value if the MP3 variable instead of needing to modify the shortcut.
You can also nest variables. If I decided to move the mp3 folder to the Temp folder (which is not a good idea, but will just be used as an example) and I created a shortcut, I would enter the path as %TEMP%\%MP3%.
Some of the more popular variables are:
SYSTEMROOT
USERNAME
USERPROFILE
TIME
DATE
COMPUTERNAME
Now that you understand variables and how to create them, their uses are endless. Variables allows you to make changes on your Computer and modify the change in one location instead of needing to hunt down a bunch of shortcuts or batch files.