views:

10475

answers:

3

How can I get Environnment variables and if something is missing, set the value?

+24  A: 

Use the System.Environment class.

The method System.Environment.GetEnvironmentVariable ()

and

System.Environment.SetEnvironmentVariable()

will do the job for you.

Daok
A: 

how do I get System.Environment.SetEnvironmentVariable() to work when I'm inside the process and I want to reset the value of the variable for it to be read from outside the process?

Please create a new question. This is not an answer to the posted question. This site does not work as a forum with discussion threads.
Binary255
+1  A: 

This will work for enviroment variable that is machine setting. For Users just change to User instead.

String EnviromentPath = System.Environment.GetEnvironmentVariable("Variable_Name", EnvironmentVariableTarget.Machine);