I am currently writing an unmanaged C++ program which works with a system environment variable. I am getting the value with GetEnvironmentVariable(…).
Now I have an C# program which may change this variable at any time, e.g. like this:
Environment.SetEnvironmentVariable("CalledPath", System.Windows.Forms.Application.ExecutablePath, EnvironmentVariableTarget.Machine);
The problem is that the C++ program does not update this variable (or its environment block in general) automatically so that I am still working with the old value unless I restart the program which is not really good.
Is there a way to update the environment block or preferably another way to read system environment variables?
Thanks in advance,
Russo
Thank you guys but I finally figured it out myself.
Since the values I receive with GetEnvironmentVariable are not the current ones I read the values directly from the registry.
The machine environment variables are stored in
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\EnvironmentI read them via the RegOpenKeyEx(…) and RegQueryValueEx(…) functions which works perfectly well.