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);}}
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: