现在的位置: 首页 > 综合 > 正文

判断系统中有没有安装某个服务

2012年06月23日 ⁄ 综合 ⁄ 共 517字 ⁄ 字号 评论关闭

代码如下:

注意:先要添加引用System.ServiceProcess

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(ServiceIsExisted("MSSQLSERVER"));
        }

        public static bool ServiceIsExisted(string serviceName)
        {
            ServiceController[] services = ServiceController.GetServices();
            foreach (ServiceController s in services)
            {
                if (s.ServiceName == serviceName)
                {
                    return true;
                }
            }
            return false;
        }  
    }

抱歉!评论已关闭.