zoukankan      html  css  js  c++  java
  • 使用ServiceController控制windows服务

    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();
    }
  • 相关阅读:
    tomcat启动startup.bat一闪而过
    shell简介
    hbase总结,值得一看
    hive的 安装和配置
    存储器管理
    银行家算法
    洛谷 2590 树的统计
    树链剖分 洛谷 3384
    2.3最大公约数与最小公倍数
    2.2 素数与合数
  • 原文地址:https://www.cnblogs.com/fromchaos/p/1658200.html
Copyright © 2011-2022 走看看