0

背景: 我创建了一个服务,该服务将在满足某些条件时触发应用程序的执行。此服务设置为在用于通过 RDP 登录系统的同一 Windows 用户帐户下运行。我还创建了通过此服务触发的 .NET 应用程序。此应用程序在磁盘上查找配置文件(在应用程序的 ProgramData 文件夹中找到)使用在配置文件中找到的设置来影响此应用程序的输出。

问题: 当用户以交互方式运行应用程序时,应用程序运行良好。但是,当服务触发应用程序运行时,应用程序似乎没有从配置文件中加载正确的值。几乎就好像从服务运行的应用程序有自己的配置文件,并且没有使用在 ProgramData 中找到的配置文件。

我只是在寻找一些关于为什么会发生这种情况的见解。通过计划任务或作为服务运行应用程序时,Windows 7 和 Windows 2008 R2 似乎出现了一些奇怪的行为。这几乎就像交互式应用程序和服务应用程序在以同一用户身份运行的同一系统上具有不同的环境......

注意:服务可执行文件也可以在与触发的应用程序相同的文件夹中找到。我希望默认情况下工作目录是服务运行目录。

  public int ExecRun()
  {
    Process proc = new Process();
    proc.StartInfo = new ProcessStartInfo
    {
       FileName = "C:\\Program Files\\TEST\\runme.exe",
       Arguments = "/DS:TEMP"
    };

    proc.Start();
    proc.WaitForExit();

    return proc.ExitCode;
  }
4

3 回答 3

0

This has been solved.

Unfortunately, I think I wasted all your time with this question. The users is running this service on a second system (other than the one they claimed was having this issue). They copied the same configuration to both systems which would've been fine if they had setup both systems the same way, but alas they did not. The file did not exist on the system throwing the error, but both systems were setup to log exceptions to the same location.

The user had to disable the second service, or setup the configuration file correctly.

于 2013-03-01T15:10:03.937 回答
0

尝试添加工作目录信息:

Process proc = new Process();
        proc.StartInfo = new ProcessStartInfo
        {
            FileName = "C:\\Program Files\\TEST\\runme.exe",
            WorkingDirectory="C:\\Program Files\\TEST",
            Arguments = "/DS:TEMP"
        };
于 2013-02-28T15:27:21.633 回答
0

听起来触发应用程序执行的服务也需要设置工作目录。如果您使用Process该类,则需要将该StartInfo.WorkingDirectory属性设置为应用程序所在的路径。

于 2013-02-28T15:28:29.310 回答