public MessageResult TryStop() { var failResult = MessageResult.MethodResult(nameof(TryStart), false); var successResult = MessageResult.MethodResult(nameof(TryStart), true); try { var serviceState = ServiceInstaller.GetServiceState(ServiceName); if (serviceState == ServiceState.NotFound) { successResult.Message = string.Format("{0} not installed!", ServiceName); return(successResult); } if (serviceState == ServiceState.Stopped || serviceState == ServiceState.StopPending) { successResult.Message = string.Format("{0} is already stopped!", ServiceName); return(successResult); } ServiceInstaller.StopService(ServiceName); return(successResult); } catch (Exception e) { failResult.Message = failResult.Message + " => " + e.Message; return(failResult); } }
public MessageResult TryStop() { var serviceName = ServiceInfo.ServiceName; var serviceState = GetServiceState(serviceName); if (serviceState == ServiceState.NotFound) { return(AppendLogsAndResult(true, string.Format("{0} not installed!", serviceName))); } if (serviceState == ServiceState.Stopped || serviceState == ServiceState.StopPending) { return(AppendLogsAndResult(true, string.Format("{0} is stopping!", serviceName))); } ServiceInstaller.StopService(serviceName); GetServiceState(serviceName); return(AppendLogsAndResult(true, string.Format("{0} stop completed!", serviceName))); }