Hi,
I've a .Net windows service which is on App server 1. From this service, I need to programmatically start and stop another .Net windows service sitting on App server 2. How do I achieve this ?
Thanks for reading.
Hi,
I've a .Net windows service which is on App server 1. From this service, I need to programmatically start and stop another .Net windows service sitting on App server 2. How do I achieve this ?
Thanks for reading.
This is an outline of what you will need to do.
System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController();
sc.ServiceName = "service name";
sc.MachineName = ".";// for local. use windows machine name here for a remote service
sc.Start();
TimeSpan timeout = new TimeSpan(0, 0, 0, 3, 0); // 3 sec
sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, ts);
if (sc.Status == System.ServiceProcess.ServiceControllerStatus.Running)
Console.WriteLine("started");
else
Console.WriteLine("failed to start");