The C# team posts answers to common questions and describes new language features
Use the System.Environment class.Specifically the GetEnvironmentVariable and SetEnvironmentVariable methods.Admitedly, this is not a question specific to C#, but it is one I have seen enough C# programmers ask, and the ability to set environment variables is new to the Whidbey release, as is the EnvironmentVariableTarget enumeration which lets you separately specify process, machine, and user.
Brad Abrams blogged on this way back at the start of this year, and followed up with a solution for pre-Whidbey users.
PingBack from http://malor.se/blog/?p=23
Using this method, you cannot retrieve the environment variable "as is" (without expanding any "%" delimited variables it may contain.) This is odd, since Environment also provides the ExpandEnvironmentVariables method, which would do the expansion if needed.