Add a reference to
System.ServiceProcess to your project and then you can get information using the
ServiceController
class, like this:
ServiceController controller = new ServiceController();
controller.MachineName = ".";
controller.ServiceName = "Tomcat6";
Console.WriteLine("Status {0}", controller.Status);
Console.WriteLine("CanPauseAndContinue {0}", controller.CanPauseAndContinue);
Console.WriteLine("CanShutdown {0}", controller.CanShutdown);
Console.WriteLine("CanStop {0}", controller.CanStop);
Console.WriteLine("DisplayName {0}", controller.DisplayName);
Console.WriteLine("ServiceType {0}", controller.ServiceType);
The class also has methods for starting and stopping the service.
Note that you have to pass the name, not the display name, to the
Name
property, you can get this by right-clicking your service and select
Properties.
Hope this helps,
Fredrik