I have problem with setting environment variables using C#.
I need to modify some environment variables on some circumstances. For example I need to modify NDSRC variable.
I use:
Environment.SetEnvironmentVariable("MY_VARIABLE", "value", EnvironmentVariableTarget.Machine);
This works fine.
Next i run some script whitch uses the variable. And now there is a problem, because script does not see the variable.
Example: Set Path variable (add a directory at the end) using
string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine) + ";c:\\";
Environment.SetEnvironmentVariable("Path", path, EnvironmentVariableTarget.Machine);
Open windows command line (Start->run->cmd.exe).
In command line type cmd
The system can not find cmd.exe: 'cmd' is not recognized as an internal or external command, operable program or batch file.
If you check Windows settings - > Environment Variables, Path is correctly set to new value. If you check in opened command prompt, it is also set.