• C# 停止或开启服务


    //启动服务
      private void btnStar_Click(object sender, EventArgs e)
      {
      
    if (bolServiceInstalled == false)
      
    return;
      
    using (System.ServiceProcess.ServiceController control = new ServiceController("Project Monitoring"))
      {
      
    if (control.Status == System.ServiceProcess.ServiceControllerStatus.Stopped)
      {
      MessageBox.Show(
    "服务启动......");
      control.Start();
      lblMessage.Text 
    = "服务已经启动......";
      }
      }
      }
      
    //停止服务
      private void btnStop_Click(object sender, EventArgs e)
      {
      
    if (bolServiceInstalled == false)
      
    return;
      
    using (System.ServiceProcess.ServiceController control = new ServiceController("Project Monitoring"))
      {
      
    if (control.Status == System.ServiceProcess.ServiceControllerStatus.Running)
      {
      MessageBox.Show(
    "服务停止......");
      control.Stop();
      lblMessage.Text 
    = "服务已经停止......";
      }
      }
      }
  • 相关阅读:
    Python标准异常topic
    文件打开的模式和文件对象方法
    python中常用的一些字符串
    zabbix3.2.0beta2 监控模版
    人工智能 --test
    Jenkins 2.7.3 LTS 发布
    Python中的socket 模块
    hibenater返回map
    去掉JavaScript Validator
    properties工具类
  • 原文地址:https://www.cnblogs.com/hantianwei/p/2104509.html
Copyright © 2020-2023  润新知