/// <summary> /// Initializes a new instance of the <see cref="WindowsService"/> class. /// </summary> /// <param name="service">The service.</param> /// <param name="description">The description.</param> public WindowsService(ServiceController service, string description) { _service = service; _description = description; _forcedStatus = ServiceForcedStatus.NONE; _serviceName = service.ServiceName; }
/// <summary> /// Forces the services. /// </summary> /// <param name="service">The service.</param> /// <param name="forcedStatus">The forced status.</param> public static void ForceServices(string[] service, ServiceForcedStatus forcedStatus) { Hashtable serviceTable = WindowsServiceManager.GetWindowsServicesTable(); WindowsService temp; foreach (string item in service) { temp = (WindowsService)serviceTable[item]; if (temp != null) { try { if ((temp.Status == ServiceControllerStatus.Running && forcedStatus == ServiceForcedStatus.RUNNING) || (temp.Status == ServiceControllerStatus.Stopped && forcedStatus == ServiceForcedStatus.STOPPED)) { // non dobbiamo fare nulla continue; } if (forcedStatus == ServiceForcedStatus.RUNNING) { temp.Service.Start(); } else if (forcedStatus == ServiceForcedStatus.STOPPED) { temp.Service.Stop(); } } catch (Exception) { } finally { } } } }
/// <summary> /// Initializes a new instance of the <see cref="WindowsService"/> class. /// </summary> public WindowsService() { _service = null; _forcedStatus = ServiceForcedStatus.NONE; }