(40)C#windows服务控制

ServiceController类

可以使用 ServiceController 类连接到现有服务并控制其行为。

 

构造函数

1.ServiceController ()

ServiceController sc  = new ServiceController();

 

2.ServiceController (String)

ServiceController sc = new ServiceController("wintest");

wintest是服务的

3.ServiceController (String, String)

 

属性

1.CanStop

返回一个bool值

如果服务在已经启动为 true;未启动则为 false

2.DisplayName

显示名称

ServiceController sc = new ServiceController("wintest");
textBox1.Text = Convert.ToString(sc.DisplayName);

 

3.Status

获得服务状态

状态有: Running ,Stopped

 

4.ServiceName

获得ServiceName名称

 

方法

ServiceController sc = new ServiceController("wintest");
sc.Start();//启动服务
sc.Stop();//停止服务

 

 

提示:可以利用webService远程控制电脑服务开关

posted @ 2018-02-27 13:49  富坚老贼  阅读(225)  评论(0编辑  收藏  举报