使用ServiceController控制windows服务
来源:互联网 发布:网络推广文案分析 编辑:程序博客网 时间:2024/05/19 15:41
1.引用System.ServiceProcess命名空间
using System.ServiceProcess;
2.声明ServiceController变量
private ServiceController _controller;
3.假设服务名为ServicesName, 编写开始服务,停止服务,重启服务的代码如下
private void StopService()
{
this._controller = new ServiceController("ServicesName");
this._controller.Stop();
this._controller.WaitForStatus(ServiceControllerStatus.Stopped);
this._controller.Close();
}
private void StartService()
{
this._controller = new ServiceController("ServicesName");
this._controller.Start();
this._controller.WaitForStatus(ServiceControllerStatus.Running);
this._controller.Close();
}
private void ResetService()
{
this._controller = new ServiceController("ServicesName");
this._controller.Stop();
this._controller.WaitForStatus(ServiceControllerStatus.Stopped);
this._controller.Start();
this._controller.WaitForStatus(ServiceControllerStatus.Running);
this._controller.Close();
}
{
this._controller = new ServiceController("ServicesName");
this._controller.Stop();
this._controller.WaitForStatus(ServiceControllerStatus.Stopped);
this._controller.Close();
}
private void StartService()
{
this._controller = new ServiceController("ServicesName");
this._controller.Start();
this._controller.WaitForStatus(ServiceControllerStatus.Running);
this._controller.Close();
}
private void ResetService()
{
this._controller = new ServiceController("ServicesName");
this._controller.Stop();
this._controller.WaitForStatus(ServiceControllerStatus.Stopped);
this._controller.Start();
this._controller.WaitForStatus(ServiceControllerStatus.Running);
this._controller.Close();
}
阅读全文
0 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服务
- 一文告诉你,NIPS 2017有多火爆 | 附PPT、视频、代码大总结
- 在Java程序中加载Native/Dynamic DLL
- 【VUE】.NET实现Tree组件双向绑定数据(2)
- LeetCode 113. Path Sum II
- mysql5.7的安装与配置(centos7环境)
- 使用ServiceController控制windows服务
- 使用swoole实现异步任务处理
- 《OpenCV3编程入门》第五章core组件进阶学习笔记part2
- <转载>eclipse(4) api显示此元素既未附加源代码也未附加 Javadoc,因此无法找到 Javadoc。
- 皇后问题
- java注释风格 与javadoc
- tomcat logs 目录下各日志文件的含义
- jQuery核心技术 (二)
- 搭建springMVC