您的位置:首页 > 其它

检查Windows服务是否启动

2013-03-14 20:21 148 查看
第一:

导入System.ServiceProcess这个名称空间

第二:遍历进程类,找到windows服务所在进程

View Code

ServiceController[] service=ServiceController.GetServices();
bool isStart = false;
for (int i = 0; i < service.Length; i++)
{
if (service[i].ServiceName.ToUpper().Equals("IISAdmin".ToUpper()))
{
if (service[i].Status == ServiceControllerStatus.Running)
{
isStart = true;
break;
}
}
}
if (isStart)
{
MessageBox.Show("服务已经启动");
}
else
{
MessageBox.Show("服务没启动");
}


最后:service[i]. 包含很多属性,根据自己的需求选择。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: