首先先引用System.ServiceProcess.dll
然后在引用命名 空间using System.ServiceProcess; ServiceController sc = new ServiceController("Server");建立服务对象 //服务运行则停止服务 if (sc.Status.Equals(ServiceControllerStatus.Running)) { sc.Stop(); sc.Refresh(); } //服务停止则启动服务 if ((sc.Status.Equals(ServiceControllerStatus.Stopped)) || (sc.Status.Equals(ServiceControllerStatus.StopPending))) { sc.Start(); sc.Refresh(); } |
c# windows服务状态、启动和停止服务
最新推荐文章于 2023-11-16 08:36:43 发布