How do I get and set Environment variables?

How do I get and set Environment variables?

Rate This
  • Comments 6

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.

[Author: SantoshZ]

Leave a Comment
  • Please add 7 and 7 and type the answer here:
  • Post
Page 1 of 1 (6 items)