private static void SetSvcDescription(Conf conf) { var description = $"{conf.Description} @<{Libs.GetCwd()}>"; var scArgs = $"description \"{conf.ServiceName}\" \"{description}\""; string err; Libs.Exec("sc", scArgs); try { var mngObj = GetServiceManagementObjectByName(conf.ServiceName); if (mngObj != null && mngObj["Description"].ToString() == description) { return; } err = "unknown reason"; } catch (Exception ex) { err = ex.ToString(); } err = $"Failed to set description for Service \"{conf.ServiceName}\": {err}"; AddLog("ERROR", err); Libs.Abort($"{err}\r\nPlease run `svc remove` to remove the Service"); }
public static void StopService(this ServiceController sc) { if (sc.Status == ServiceControllerStatus.Stopped) { Console.WriteLine($"Service \"{sc.ServiceName}\" is already stopped"); return; } var startMsg = $"Stopping service \"{sc.ServiceName}\""; var timeoutMsg = $"Failed to stop the service, " + $"please refer to {Libs.GetCwd()}svc.log to see what happened"; var okMsg = $"Stopped Service \"{sc.ServiceName}\""; Libs.Timeout(sc.StopSvc, Consts.MAX_SERVICE_START_STOP_SECONDS, startMsg, timeoutMsg, okMsg); }