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

代码如下:

注意:先要添加引用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;
        }  
    }

原文地址:https://www.cnblogs.com/tianguook/p/2567728.html