C# windows服务:如何检测指定的Windows服务是否启动

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