使用ServiceController控制windows服务
来源:互联网 发布:3d直选遗漏数据统计 编辑:程序博客网 时间:2024/05/17 06:41
ServiceController控制windows服务
1.在项目中“引用”=》.net选项中找到System.ServiceProcess
2.using System.ServiceProcess;
//启动服务
private void button13_Click(object sender, EventArgs e) { try { ServiceController sc = new ServiceController("WapSearchWCFService"); if (sc.Status == ServiceControllerStatus.Stopped) { sc.Start(); sc.WaitForStatus(ServiceControllerStatus.Running); } sc.Close(); this.label27.Text = "已启动"; } catch { MessageBox.Show("启动失败!"); } }
//停止服务
private void button14_Click(object sender, EventArgs e) { try { ServiceController sc = new ServiceController("WapSearchWCFService"); if (sc.Status == ServiceControllerStatus.Running) { sc.Stop(); sc.WaitForStatus(ServiceControllerStatus.Stopped); } sc.Close(); this.label27.Text = "已停止"; } catch { MessageBox.Show("停止失败!"); } }
//重新启动
private void button15_Click(object sender, EventArgs e) { try { ServiceController sc = new ServiceController("WapSearchWCFService"); if (sc.Status == ServiceControllerStatus.Running) { sc.Stop(); sc.WaitForStatus(ServiceControllerStatus.Stopped); this.label27.Text = "已停止"; } if (sc.Status == ServiceControllerStatus.Stopped) { sc.Start(); sc.WaitForStatus(ServiceControllerStatus.Running); this.label27.Text = "已启动"; } sc.Close(); MessageBox.Show("重新启动成功!"); } catch { MessageBox.Show("重新启动失败!"); } }
2 0
- 使用ServiceController控制windows服务
- 使用ServiceController控制windows服务
- ServiceController控制windows服务
- 使用ServiceController监视和控制Windows服务
- C#使用ServiceController控制windows服务
- 通过ServiceController控制windows服务
- 使用ServiceController类监视和控制Windows服务
- ServiceController操作Windows服务
- ServiceController操作Windows服务
- ServiceController操作Windows服务
- ServiceController操作Windows服务
- ServiceController操作Windows服务
- ServiceController操作Windows服务 监控Windows服务
- C# 应用ServiceController控制自定义windows service
- ServiceController启动停止服务
- ServiceController
- 使用WMI来控制Windows服务
- C#控制Windows服务
- java Debug
- 公司永远都不会告诉你的
- WPF控件开发之自定义控件(5)
- oracle regexp_like实现字符串中判断某个值是否存在
- fashion modules for pythoner
- 使用ServiceController控制windows服务
- Present ViewController详解
- 敏捷是一场关于适者生存的进化
- 编译nginx并加入chunkin-nginx-module模块
- Linux登录系统后了解用户、用户组、登录的终端以及root用户强制指定终端用户下线的小结
- linux grep命令
- Note for Oracle
- Binary Tree Zigzag Level Order Traversal
- 将文件转换成字符串,常用于读取网站模板