环境变量值修改

环境变量值修改

问题描述:

亲爱的所有人
我需要将值设置为环境变量
我使用了下面的代码行

Dear All
I need to set value to an environment variable
I used the below line of code

Environment.SetEnvironmentVariable("TRACE", chkLogTrace.Checked.ToString(), EnvironmentVariableTarget.Machine);


它抛出System.Security.SecurityException

如何修改环境变量中的值?????

在此先感谢


Its throwing System.Security.SecurityException

How to modify the values in environment variable ?????

Thanks in advance

该代码似乎是正确的.要为EnvironmentVariableTarget.Machine设置环境变量,您需要以管理员身份登录或以管理员权限运行程序.
看到这里:
http://msdn.microsoft.com/de-de/library/96xafkes.aspx [ ^ ]
然后在这里:
http://msdn.microsoft.com/de-de/library/system. security.permissions.environmentpermission.aspx [ ^ ]
The code seems to be correct. To set the environment variable for EnvironmentVariableTarget.Machine you need to be logged in as administrator or run your program with admin rights.
See here:
http://msdn.microsoft.com/de-de/library/96xafkes.aspx[^]
and here:
http://msdn.microsoft.com/de-de/library/system.security.permissions.environmentpermission.aspx[^]