C# 实现安装C#写的系统服务 不依赖InstallUtil

C# 专栏收录该内容
83 篇文章 0 订阅

反编译的 InstallUtil  


	/// <summary>
        /// 安装服务
        /// using System.Configuration.Install
        /// </summary>
        /// <param name="AssemblyFile">程序集</param>
        /// <param name="Install">true 安装  false 卸载</param>
        public void InstallServer(String AssemblyFile,Boolean Install = true)
        {
            TransactedInstaller transactedInstaller = new TransactedInstaller();
            List<String> arrayList = new List<String>();
            Assembly assembly = null;
            //arrayList.Add("/LogToConsole=false");
            //XXServer, Version=3.425.2015.320, Culture=neutral, PublicKeyToken=null
            if (AssemblyFile.Contains("Version") && AssemblyFile.Contains("Culture") && AssemblyFile.Contains("PublicKeyToken"))
            {
                assembly = Assembly.Load(AssemblyFile);
            }
            else
            {
                assembly = Assembly.LoadFrom(AssemblyFile);
            }
            AssemblyInstaller value = new AssemblyInstaller(assembly, arrayList.ToArray());
            transactedInstaller.Installers.Add(value);
            transactedInstaller.Context = new InstallContext("log.txt", arrayList.ToArray());
            try
            {
                IDictionary stateSaver = new Hashtable();
                transactedInstaller.Install(stateSaver);
                transactedInstaller.Uninstall(null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }


  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值