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

标签 .net windows service environment-variables

我需要为 .NET 2.0 中使用自己的用户帐户运行的 Windows 服务更改环境变量 Environment.GetEnvironmentVariable("TMP")。服务器是 Windows Server 2003, SP2。谁能告诉我如何为该用户更改 Windows 环境变量?

最佳答案

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

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

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

关于.net - 如何更改 Windows 服务环境路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2544018/

相关文章:

.net - 循环引用导致内存泄漏?

.net - 自定义文本框的边框

windows - 如何递归地将特定模式的文件复制到 Windows 上的单个平面文件夹中?

windows - 在 Windows 中运行 .bat 文件是否会生成任何系统日志?

当我将脚本作为 Windows 服务运行时,Python 代码无法按预期工作

Android - 使用 CommonWare 的 locpoller 时出现问题

c# - 如何使用反射在 C# 中获取自动属性的默认值?

.net - 沙箱IronPython?

c++ - 关于记录时间的程序/脚本的建议

android - 优先安排崩溃的 android 服务的重启