Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want to know what will be the status of started service and starting service in c#.
I want to use this status to run progress bar till service started.
Posted

1 solution

Add a reference to System.ServiceProcess to your project and then you can get information using the ServiceController class, like this:
C#
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900