Jun 29

c# windows服务状态、启动和停止服务 不指定

zpgm , 22:28 , Asp.Net 2.0 , 评论(3) , 引用(0) , 阅读(2174) , Via 本站原创 | |
首先先引用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();
             }

Tags: ,
est Email Homepage
2010/03/09 17:40
g Email Homepage
2009/09/15 13:04
ch
2009/04/09 15:54
angerbadcoolcrycelebrateenvyfeargrinkillloveshuaishockquestionpukepigshysleepysmilebeatstealthilyzanuplookunhappythumbdownsweat
分页: 1/1 第一页 1 最后页
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]