I know that I can query any environment variable by calling:
System.Environment.GetEnvironmentVariable();
Now for example, I want the value of windir, that is %SystemRoot%. However, the function interpretes it as C:\Windows (which is the value of SystemRoot).
I get the same behaviour by querying the registry key with Registry.LocalMachine.OpenSubKey()
Is there a way to get variable names from an environment variable instead of their paths? (I need it in order to easily switch between multiple installed versions of a SDK I work with.)
As far as I know, the only way to do that, is to read the environment variable directly from the registry and specify that you do not want it expanded:
registryKey.GetValue("PATH", "", RegistryValueOptions.DoNotExpandEnvironmentNames);
See the docs for RegistryValueOptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With