.net 如何更改Windows服务环境路径

.net 如何更改Windows服务环境路径,.net,windows,service,environment-variables,.net,Windows,Service,Environment Variables,我需要更改.NET2.0中使用自己的用户帐户运行的Windows服务的环境变量environment.GetEnvironmentVariable(“TMP”)。服务器是Windows server 2003 SP2。有人能告诉我如何更改该用户的Windows环境变量吗?只需在Main或OnStart方法中设置环境变量: Environment.SetEnvironmentVariable("TMP", @"c:\temp"); 使用SetEnvironmentVariable()只会更改

我需要更改.NET2.0中使用自己的用户帐户运行的Windows服务的环境变量environment.GetEnvironmentVariable(“TMP”)。服务器是Windows server 2003 SP2。有人能告诉我如何更改该用户的Windows环境变量吗?

只需在Main或OnStart方法中设置环境变量:

  Environment.SetEnvironmentVariable("TMP", @"c:\temp");

使用SetEnvironmentVariable()只会更改进程运行实例的环境,而不会更改用户的系统环境。

否,我确实需要在Windows中更改它,可能是在注册表中?好的,我会尝试一下,谢谢。