Appending to PATH environment variable
Well, I don't quite get it! I am trying to apend to the environment variable PATH using C#, however some things related to this is difficult to find an answer for!
I can retrieve the value of the PATH in two ways, either using direct access to the Windows registry using the RegistryKey class, or using the Environment.GetEnvironmentVariable method. In both cases I will get the expanded value; that is where the %SystemRoot% has been replaced by the actual value. I thought that the method Environment.ExpandEnvironmentVariables was exactly for this purpose!
So the thing is that I can't seem to get the raw value out of the registry, and I need that for writing the new value, since otherwise I would loose the wildcards! How do I do this? Or is there a smarter way of appending to the PATH variable, without doing all this work (checking existency, string concatenation etc.)?
Moreover I have heard that you need to do some kind of broadcast after setting the new variable, something about letting other programs know of the changes! How do I do this, and is there a smart way to do this in C#?
Thanks :)
Jacob.
|