简体   繁体   中英

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM