Defining current environment variables

Application: C #, .NET4, Windows 7

When the application starts, it receives a copy of the current environment variables, and they remain constant for the life of this application. I want to know how to get the actual current environment variables, letting me respond to changes.

Do I need to go to the registry? I was thinking about creating cmd.exe and dumping the output from the set, but I would prefer something less hacky.

thank

+3
source share
1 answer

The following overload can give you what you want:

String Environment.GetEnvironmentVariable(String, EnvironmentVariableTarget)

Try to pass EnvironmentVariableTarget.Useror EnvironmentVariableTarget.Machine.

To get all the variables, call

IDictionary Environment.GetEnvironmentVariables(EnvironmentVariableTarget)
+1

Source: https://habr.com/ru/post/1764709/


All Articles