public MessageResult TryStart() { var failResult = MessageResult.MethodResult(nameof(TryStart), false); var successResult = MessageResult.MethodResult(nameof(TryStart), true); try { var serviceState = ServiceInstaller.GetServiceState(ServiceName); if (serviceState == ServiceState.NotFound) { failResult.Message = string.Format("{0} not installed!", ServiceName); return(failResult); } if (serviceState == ServiceState.Running || serviceState == ServiceState.StartPending) { successResult.Message = string.Format("{0} is already running!", ServiceName); return(successResult); } ServiceInstaller.StartService(ServiceName); return(successResult); } catch (Exception e) { failResult.Message = failResult.Message + " => " + e.Message; return(failResult); } }
public MessageResult TryStart() { var serviceName = ServiceInfo.ServiceName; var serviceState = GetServiceState(serviceName); if (serviceState == ServiceState.NotFound) { return(AppendLogsAndResult(false, string.Format("{0} not installed!", serviceName))); } if (serviceState == ServiceState.Running || serviceState == ServiceState.StartPending) { return(AppendLogsAndResult(true, string.Format("{0} is already running!", serviceName))); } ServiceInstaller.StartService(serviceName); return(AppendLogsAndResult(true, string.Format("{0} start completed!", serviceName))); }