Get all Services on a System using C#


ServiceController class defined in the System.ServiceProcess namespace is used to work with services. ServiceController.GetServices static method gets all services installed on a machine.

This code snippet demonstrates how to get all services installed on a machine and list them in a ListBox control.

Create a Windows Forms application, add a ListBox control onto the Form, add following code and call GetAllServices method on the Form's load event handler.


private
void GetAllServices()
{
foreach (ServiceController service in ServiceController.GetServices())
{
string serviceName = service.ServiceName;
string serviceDisplayName = service.DisplayName;
string serviceType = service.ServiceType.ToString();
string status = service.Status.ToString();
ServicesListBox.Items.Add(serviceName +
" " + serviceDisplayName +
serviceType +
" " + status);
}
}


Similar Articles
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.