C# 操作系统服务(service)代码

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

C# 操作系统服务(service)代码
可以控制启动和停止系统服务
  private bool StopService(string StopServiceName)
        {  
            ServiceController service = new ServiceController(StopServiceName);
            try 
            {   
                service.Stop();   
                service.WaitForStatus(ServiceControllerStatus.Stopped);
            }  
            catch(Exception) 
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// 开启服务
        /// </summary>
        private bool StartService(string StartServiceName)
        { 
            ServiceController service = new ServiceController(StartServiceName);
            try 
            {   
                 service.Start();  
                 service.WaitForStatus(ServiceControllerStatus.Running);
            }  
            catch (Exception)
            {
                return false;
            }
            return true;
        }