/// <summary> /// Queries the WMI service for it's status and returns true if it's running, false otherwise /// </summary> /// <returns>true of the WMI service is running, false otherwise</returns> private static bool IsWMIServiceRunning() { var sc = new System.ServiceProcess.ServiceController("Winmgmt"); switch (sc.Status) { case System.ServiceProcess.ServiceControllerStatus.Running: sc.Dispose(); return(true); //break; default: sc.Dispose(); return(false); //break; } }
public static bool StopService(string serviceName, TimeSpan timeSpan) { if (!ExistService(serviceName)) { return(false); } System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(serviceName); if (sc.Status != System.ServiceProcess.ServiceControllerStatus.Stopped && sc.Status != System.ServiceProcess.ServiceControllerStatus.StopPending) { sc.Stop(); } sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped, timeSpan); var isok = sc.Status == System.ServiceProcess.ServiceControllerStatus.Stopped; sc.Close(); sc.Dispose(); return(isok); }
/// <summary> /// 停止Windows服务 /// </summary> /// <param name="serviceName">服务名称</param> public static void WindowsServiceStop(string serviceName) { System.ServiceProcess.ServiceController control = new System.ServiceProcess.ServiceController(serviceName); control.Stop(); control.Dispose(); }
/// <summary> /// 停止Windows服务 /// </summary> /// <param name="serviceName">服务名称</param> public static void WindowsServiceStop(string serviceName) { System.ServiceProcess.ServiceController control = new System.ServiceProcess.ServiceController(serviceName); control.Stop(); control.Dispose(); }