无法在Windows服务中启动.exe应用程序

时间:2017-02-02 05:37:37

标签: c# windows-services

我已经编写了一个Windows服务来启动示例Windows应用程序。一旦服务加载它应该启动应用程序,但在我的情况下即使服务启动它也无法启动我的应用程序。

以下是代码:

  protected override void OnStart(string[] args)
    {
        this.WriteToFile("Simple Service started {0}");
        Process.Start("‪D:\\demo.exe");
        this.WriteToFile("Simple Service ended {0}");

    }  

2 个答案:

答案 0 :(得分:1)

可能是您的服务使用System.ServiceProcess.ServiceAccount.LocalSystem帐户

运行

转到ServiceInstaller.cs文件

转到InitializeComponent()方法

请根据您的代码更改以下行

this.serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.User

注意:服务安装时会询问Windows登录ID /密码。

请阅读MSDN的this wonderfule artical

答案 1 :(得分:0)

  ProcessStartInfo pinfo = new ProcessStartInfo("‪D:\\demo.exe");
  pinfo.Verb = "runas";
  Process.Start(pinfo);
相关问题