zoukankan      html  css  js  c++  java
  • C# windows服务(二) 服务安装与卸载

    新建winform程序

    添加引用:System.Configuration.Install

      

    界面设计:

      

      代码:

    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            // 服务 安装
            private void btn_Install_Click(object sender, EventArgs e)
            {
    
                string serverFileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GZ.PlanService.exe");
    
                var state = new Hashtable();
    
                AssemblyInstaller installer = new AssemblyInstaller(serverFileName, null);
                installer.UseNewContext = true;
                installer.Install(state);
                installer.Commit(state);
    
    
            }
            // 服务卸载
            private void btn_UnInstall_Click(object sender, EventArgs e)
            {
                string serverFileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GZ.PlanService.exe");
                var state = new Hashtable();
    
                AssemblyInstaller installer = new AssemblyInstaller(serverFileName, null);
                installer.UseNewContext = true;
                installer.Uninstall(state);
                installer.Commit(state);
            }
    
    
        }

      rew

      

  • 相关阅读:
    ios手机和Android手机测试点区别
    业务下的测试总结
    Mac下web自动化环境部署
    Mac下查找python的安装位置以及第三方库
    简易计算器
    递归
    可变参数
    方法的重载
    方法
    三角形
  • 原文地址:https://www.cnblogs.com/GarsonZhang/p/13935973.html
Copyright © 2011-2022 走看看