How do I get and set Environment variables?

Published 02 December 04 09:01 AM

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]

Filed under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Sheeshers said on December 3, 2004 7:49 AM:
Can someone answer the question posted at the URL above?
# Ernst Kuschke (C# MVP) said on December 12, 2004 11:22 PM:
Something I've wondered about a couple of times: When do environment variables get loaded? Does the OS periodically check for changes? Does it load them per session? No? Yes?
# FAQ C# said on April 12, 2005 10:01 AM:
# FAQ C# (par Yannick Lejeune) said on August 23, 2005 4:48 AM:
# Martin’s Blog » Blog Archive » log4net and the LocalApplicationData folder said on December 11, 2007 3:22 PM:

PingBack from http://malor.se/blog/?p=23

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

This Blog

Syndication

Page view tracker