public string IsStopDispatchHander(out string statusCode, out string errMsg) { statusCode = "0000"; errMsg = ""; if (!ServiceToolEx.IsServiceRunning(dispatchServerName)) { errMsg = dispatchServerName + "服务未运行"; statusCode = "4000"; return(""); } ServiceController service = ServiceToolEx.StopService(dispatchServerName); if (service == null) { errMsg = dispatchServerName + "服务停止失败"; statusCode = "4001"; return(""); } if (!ServiceToolEx.IsServiceRunning(dispatchServerName)) { return(dispatchServerName + "服务已停止"); } else { errMsg = dispatchServerName + "服务停止失败!" + ErrorPolicy; statusCode = "4005"; return(""); } }
// 停止服务 public string IsStopCoreHander(out string statusCode, out string errMsg) { statusCode = "0000"; errMsg = ""; if (!ServiceToolEx.IsServiceRunning(serverName)) { errMsg = serverName + "服务未运行"; statusCode = "4000"; return(""); } ServiceController service = ServiceToolEx.StopService(serverName); if (service == null) { errMsg = serverName + "服务停止失败"; statusCode = "4001"; return(""); } if (ServiceToolEx.IsServiceRunning(serverName)) { errMsg = serverName + "服务停止失败!" + ErrorPolicy; statusCode = "4005"; return(""); } string dispatchInfo = IsStopDispatchHander(out statusCode, out errMsg); return(serverName + "服务已停止;" + dispatchInfo); }
public string IsRestartDispatchHander(out string statusCode, out string errMsg) { statusCode = "0000"; errMsg = ""; if (!ServiceToolEx.IsServiceExist(dispatchServerName)) { errMsg = dispatchServerName + "服务不存在请先注册"; statusCode = "4000"; return(""); } ServiceController service; if (ServiceToolEx.IsServiceRunning(dispatchServerName)) { service = ServiceToolEx.StopService(dispatchServerName); if (service == null) { service = null; errMsg = dispatchServerName + "服务停止失败"; statusCode = "4001"; return(""); } if (ServiceToolEx.IsServiceRunning(dispatchServerName)) { errMsg = dispatchServerName + "服务停止失败!" + ErrorPolicy; statusCode = "4005"; return(""); } } service = ServiceToolEx.StartService(dispatchServerName, new string[0]); if (service == null) { errMsg = dispatchServerName + "服务启动失败"; statusCode = "4002"; return(""); } if (ServiceToolEx.IsServiceRunning(dispatchServerName)) { return(serverName + "服务已重新启动"); } else { errMsg = dispatchServerName + "服务启动失败!" + ErrorPolicy; statusCode = "4005"; return(""); } }
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); }