views:

58

answers:

3

How can I read a user specific environment variable? I know how to get a system wide one, like

Environment.GetEnvironmentVariable("SOMETHING");

Thanks in advance!

+1  A: 

Use second overload of GetEnvironmentVariable which let's you specify EnvironmentVariableTarget.

Giorgi
+1  A: 

It's the same method, just set the second parameter to be User as:

System.Environment.GetEnvironmentVariable("varName", EnvironmentVariableTarget.User);
ho1
+4  A: 

Use the other overload of the Environment.GetEnvironmentVariable Method that lets you specify the EnvironmentVariableTarget.

Environment.GetEnvironmentVariable(variable, target);

target can be:
EnvironmentVariableTarget.Process,
EnvironmentVariableTarget.User,
EnvironmentVariableTarget.Machine.

Jaroslav Jandek