In the "good old days" the "environment" was a part of computer memory where DOS saved global information that might be required by any program. So, for example, if you needed a convenient way to tell your "Recipe" program the path and name of the directory where recipes were saved, you put it in the environment. (Everybody had a Recipe program back in the good old days.) In DOS, you would "Set" the environment from a DOS command prompt:
C:\> SET AboutVB="GREAT!!!"
C:\> SET AboutVB
GREAT!!
It still works exactly that way! You can try the example above in a Command Prompt window. Don't worry, it won't change your whole Windows environment. It's only saved while that Command Prompt window is present. The Command Prompt isn't DOS, it's just a process that goes away again. The old "DOS" was a program named Command.Com that was loaded when your computer booted and controlled everything from that point on. These days, Command Prompt input is processed by a "shell" program named Cmd.Exe that is normally not even running.
You can program the overall Windows environment. Although the environment is a golden oldie that was invented way before Windows, it's unlikely that it will go away in the forseeable future. Compared with the other software nightmares in a modern OS like Vista, the environment is simply no trouble to continue to support. Besides, a lot of software still uses it. It's especially popular, and even has more advanced capability, in Microsoft's server products where the sysadmins are more used to writing scripts and getting things done at the command line.
Microsoft is in enough trouble "breaking" other people's software with new changes. They're not going to create a huge problem by failing to support the environment. So, it might not be the best way to accomplish programming goals. (Microsoft uses XML a lot, although they still use the environment too!) But it's there and it's available. Besides, the chances are good that you'll have to maintain an older system that still uses it sometime in your career.
The problem is that like everything else, Microsoft has added layers and layers on top of it. Let's find out about the layers that have been added in .NET to work with the environment.
The Environment Variables Windows Dialog
Just to get up to speed, let's look at the environment in Windows XP. (You have to be logged on as "Administrator" to do most of the things described here.) To check out the environment, bring up the My Computer properties window. Use the System icon under Performance and Maintenance in Control Panel. You'll see something like the illustration below:
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
The illustration shows that the environment is divided between System variables and User variables. Environment variables are saved in the Windows Registry. User variables are kept in HKEY_CURRENT_USER\ Environment. System variables are in HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ Control\ Session Manager\ Environment.
(Actually, there are three types of environment variables. Although the venerable old Autoexec.bat file from DOS is pretty much ignored by Windows these days - and you're not encouraged to use it now - environment variables set in Autoexec.bat are still recognized ... somewhat. First, there's a registry setting that must have the right value. In HKEY_CURRENT_USER\ Software\ Microsoft\ Windows NT\ CurrentVersion\ Winlogon, set ParseAutoexec to 1. Then the following illustration shows that they're still there, but Windows still won't show them to you!)
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
The Environment Variables Windows dialog provides buttons to create New variables, Edit existing ones, and Delete existing variables. Changes you make here are saved permanently. If you create a New variable here, it will still be present even if you reboot because it's saved in the Registry. Environment variables are not case sensitive so if you create a New AboutVB environment variable, you can reference it as aboutvb.
Predefined Environment Variables
You can use environment variables that are assigned by the system as well as variables that you define. There are two kinds of "predefined" environment variables: static and dynamic. %UserName% and %WinDir% are examples of static variables. Their values stay the same unless they're explicitly changed. %Date% and %ErrorLevel% are examples of dynamic variables since the value changes.
If you use the Environment Variables Windows dialog to create a New variable, the value assigned by the system is substituted immediately. Create a New variable with the value %UserName% to see this yourself. But this dialog doesn't even recognize dynamic predefined variables. Try creating a New variable with the value %Date%. You can see the results in the illustration below:
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
Search for environment variables at MSDN to see the complete list of predefined variables. Part 2 of the VB.NET Express Tutorial has some practical advice on how to search for information on the Web.

