コード例 #1
0
        public bool StopOPCServer(out string errMsg)
        {
            errMsg = "";
            if (!IsNeedOPCServer)
            {
                errMsg = "检测到核心服务不需要OPCServer,停止OPCServer失败";
                return(false);
            }
            string[]      services    = ServiceToolEx.GetLocalHostServerList();
            List <string> kepServices = new List <string>();

            foreach (string servicesName in services)
            {
                if (servicesName.ToUpper().Contains("KEPSERVEREX"))
                {
                    kepServices.Add(servicesName);
                }
            }
            if (kepServices.Count == 0)
            {
                errMsg = "检测到本地计算机没有安装KepServer,无法停止其服务";
                return(false);
            }
            errMsg = "";
            foreach (string servicesName in kepServices)
            {
                if (!ServiceToolEx.StopService(servicesName, out string err))
                {
                    errMsg = errMsg + err;
                }
            }
            if (string.IsNullOrWhiteSpace(errMsg))
            {
                return(true);
            }
            return(false);
        }