I have a problem setting environment variables using C #.
I need to change some environment variables in some circumstances. For example, I need to change the NDSRC variable.
I use:
Environment.SetEnvironmentVariable("MY_VARIABLE", "value", EnvironmentVariableTarget.Machine);
This works great.
Then I run some script whitch uses a variable. And now there is a problem because the script does not see the variable.
Example: Set the Path variable (add a directory to the end) with
string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine) + ";c:\\"; Environment.SetEnvironmentVariable("Path", path, EnvironmentVariableTarget.Machine);
Open the Windows command prompt (Start-> run-> cmd.exe).
At the command prompt, type cmd
The system cannot find cmd.exe: 'cmd' is not recognized as an internal or external command, operating program, or batch file.
If you check the settings of Windows -> Environment Variables, Path will be correctly set to the new value. If you close the open command line, it will also be installed.
c # environment-variables
Pablo not picasso
source share