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

      

  • 相关阅读:
    HDU4565
    CF861D
    UVA 11651
    HDU5950
    POJ3267
    POJ1094
    POJ1905
    HDU3567
    进程的同步与互斥
    预防死锁,检测死锁,避免死锁,解除死锁....
  • 原文地址:https://www.cnblogs.com/GarsonZhang/p/13935973.html
Copyright © 2011-2022 走看看