Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
How do i know that a Specific system Service is started or stopped in asp.net and C#. I just want to fetch status of the particular service whether that system service is start or stopped.Please help me to do this coding in asp.net.
Posted
Comments
Sampath Lokuge 10-Jun-14 4:36am    
Which service do you need to check ?
Kornfeld Eliyahu Peter 10-Jun-14 5:02am    
Services of which computer? The server or the client?

1 solution

Use below code . It will give you all services and status.And put this service name and status in one custome lsit variable.

C#
foreach (ServiceController services in ServiceController.GetServices())
             {
                 string path = "Win32_Service.Name='" + services.ServiceName + "'";
                 ManagementPath p = new ManagementPath(path);
                 ManagementObject ManagementObj = new ManagementObject(p);
                 if (ManagementObj["Description"] != null)
                 {
                     string serviceName = services.ServiceName;
                  string status=   services.Status.ToString();
                 }
         }
 
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