1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
public void CheckServerState(string ServiceName) { ServiceController[] service = ServiceController.GetServices(); bool isStart = false; bool isExite = false; for (int i = 0; i < service.Length; i++) { if (service[i].ServiceName.ToUpper().Equals(ServiceName.ToUpper())) { isExite = true; server = service[i]; if (service[i].Status == ServiceControllerStatus.Running) { isStart = true; break; } } } if (!isExite) { this.label1.Text = ("不存在此服务"); }else{ if (isStart) { this.label1.Text = ("服务已经启动"); } else { this.label1.Text = ("服务没启动"); } } } |
from:http://www.cnblogs.com/lujin49/p/3527704.html