Mahi
Mahi

Reputation: 1

Unable to launch .exe application in Windows Service

I have written a windows service to launch a sample windows application. Once the service loads it should start the application but in my case even though service starts it is not able to launch my application.

Below is the code:

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

    }  

Upvotes: 0

Views: 1685

Answers (2)

Darshan Faldu
Darshan Faldu

Reputation: 1605

It might be your service running with System.ServiceProcess.ServiceAccount.LocalSystem account

Goto your ServiceInstaller.cs file

Goto InitializeComponent() method

Please change below line as per your code

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

NOTE: It will ask windows login id / password while service installation.

please read this wonderfule artical of MSDN

Upvotes: 1

Fadia Jabeen
Fadia Jabeen

Reputation: 58

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

Upvotes: 0

Related Questions