如何重启Windows服务

添加引用:
  1. System.ServiceProcess

 

编写代码:

             try
            {
                ServiceController service = new ServiceController(cleeService.ServiceName, m_host);
                if (service.Status == ServiceControllerStatus.Running || service.Status == ServiceControllerStatus.Paused)
                {
                    service.Stop();
                    service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(10.0));
                }
                service.Start();
                service.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(10.0));
            }
            catch (Exception ex)
            {
                throw;
            }

 

你可能感兴趣的:(如何重启Windows服务)