/// <summary> /// Checks if all the services are set to startup manually. /// </summary> /// <returns>True is all the services are set to startup manually.</returns> public bool IsServicesSetToManualStartup() { foreach (var serviceCode in ServiceList) { // SQLWriter is set to Automatic by SQL Server even if we change the startup to manual, let's ignore it. var service = new ServiceObject(serviceCode); if (!serviceCode.Equals("SQLWriter", StringComparison.InvariantCultureIgnoreCase) && !service.IsStartupManual()) { return(false); } } return(true); }
/// <summary> /// Sets the specified service to startup manually. /// </summary> /// <param name="serviceCode">The name of the service</param> private static void SetServiceTypeManual(string serviceCode) { try { var service = new ServiceObject(serviceCode); if (!service.IsStartupDisabled()) { service.SetStartupManual(); } } catch (Exception) { } }
/// <summary> /// Starts the specified service. /// </summary> /// <param name="service"> The service to start /// </param> /// <returns> /// The start service. /// </returns> private bool StartService(ServiceController service) { try { service.Refresh(); var serviceObj = new ServiceObject(service.ServiceName); if (service.Status == ServiceControllerStatus.Stopped && !serviceObj.IsStartupDisabled()) { ReportProgress(string.Format("Starting {0}...\r\n", service.DisplayName)); service.Start(); service.WaitForStatus(ServiceControllerStatus.Running); } return(true); } catch (Exception) { return(false); } }