Thomas
Thomas

Reputation: 3358

Determine current environment variables

App: C#, .NET4, Windows 7

When an app starts up, it gets a copy of the current environment variables and they stay constant for the life of that app. I want to know how to get the actual current environment variables, allowing me to react to changes.

Do I need to go to the registry? I've pondered spawning a cmd.exe and dumping the output of set, but I'd prefer something less hacky.

Thanks

Upvotes: 3

Views: 866

Answers (1)

Jeffrey L Whitledge
Jeffrey L Whitledge

Reputation: 59443

The following overload might give you what you want:

String Environment.GetEnvironmentVariable(String, EnvironmentVariableTarget)

Try passing EnvironmentVariableTarget.User or EnvironmentVariableTarget.Machine.

To get all of the variables, call

IDictionary Environment.GetEnvironmentVariables(EnvironmentVariableTarget)

Upvotes: 1

Related Questions