ServiceController
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.ServiceProcess;
5
6 namespace Study
7 {
8 public class ServiceInfo
9 {
10 public void ShowServiceInfo()
11 {
12 ServiceController[] services=System.ServiceProcess.ServiceController.GetServices();
13 System.Console.WriteLine("Service名称 Service显示名称 Service状态");
14 for (int i = 0; i < services.Length; i++)
15 {
16 System.Console.WriteLine(string.Format("{0} {1} {2}", services[i].ServiceName, services[i].DisplayName, services[i].Status.ToString()));
17 }
18 }
19 }
2 using System.Collections.Generic;
3 using System.Text;
4 using System.ServiceProcess;
5
6 namespace Study
7 {
8 public class ServiceInfo
9 {
10 public void ShowServiceInfo()
11 {
12 ServiceController[] services=System.ServiceProcess.ServiceController.GetServices();
13 System.Console.WriteLine("Service名称 Service显示名称 Service状态");
14 for (int i = 0; i < services.Length; i++)
15 {
16 System.Console.WriteLine(string.Format("{0} {1} {2}", services[i].ServiceName, services[i].DisplayName, services[i].Status.ToString()));
17 }
18 }
19 }
20 }
static void Main(string[] args)
{
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.ShowServiceInfo();
Console.ReadLine();
}