[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 656
  • Last Modified:

ASP.Net/C# - how to check if service is started or not in code

I need to check in my C# code in my web app if a windows service is started or not and then show an image for start and stop based on that.  Any idea what syntax I can use to check if it is started based on a service name?
0
sbornstein2
Asked:
sbornstein2
1 Solution
 
jinalCommented:
I hope you have all neccessary permission for that.

use ServiceControl class for that.

For that you have to add System.ServiceProcess assembly refrence.
http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.aspx

System.ServiceProcess.ServiceController controller = new System.ServiceProcess.ServiceController("name of the service")
            controller.Status.ToString();

Open in new window

0
 
sbornstein2Author Commented:
awesome thanks
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now