.net 自带打包程序类的写法

一个打包程序setup.exe,要想在安装或卸载之间进行其它操作,需要如下操作。

 

首先建立一个类库:  

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Configuration.Install; //引用此命名空间

namespace myInstall
{

 
    [RunInstaller(true)] //序列话,否则无法运行到此程序
    public class Installer1 : Installer //首先继承Installer类
    {

 

   // 自定义的方法,需要做的事情
        private void InstallDateBase()
        {

            System.Reflection.Assembly Asm;

            Asm = System.Reflection.Assembly.GetExecutingAssembly();

            System.IO.FileInfo FileInfo = new System.IO.FileInfo(Asm.Location.Substring(0, Asm.Location.LastIndexOf("\\") + 1));

            ProcessStartInfo psi = new ProcessStartInfo();

            psi.FileName = FileInfo.FullName +"Install.bat";//  "飞鸽.exe";

            psi.UseShellExecute = true;

            Process.Start(Asm.Location.Substring(0, Asm.Location.LastIndexOf("\\") + 1) + "Install.bat");        

        }

        //在点击安装“完成”之前要执行的一段代码

   public override void Install(System.Collections.IDictionary stateSaver)
        {

            try
            {

                base.Install(stateSaver);

                this.InstallDateBase();//调用上面的方法

            }

            catch
            {

                throw;

            }

        }

    //卸载完成之前可执行此代码

        public override void Uninstall(System.Collections.IDictionary stateSaver)
        {
            base.Uninstall(stateSaver);
        }

   //在提交时执行代码

        public override void Commit(System.Collections.IDictionary stateSaver)
        {
            base.Commit(stateSaver);

        }

   //回滚时执行代码

        public override void Rollback(System.Collections.IDictionary stateSaver)
        {
            base.Rollback(stateSaver);
        } 
    }
}

生成它之后,在setup.exe项目中添加此dll,然后在自定义操作时找到此类,如下图:


 

QQ%E6%88%AA%E5%9B%BE%E6%9C%AA%E5%91%BD%E5%90%8D.gif 

 

然后再重新生成setup.exe程序,既可完成需要做的工作。

 

若选择第二种方式添加卸载程序,需要设置其快捷方式的Arguments属性值为:/x { E9E37B3F-FB17-4002-89CE-E1210057E6C4}

转载于:https://www.cnblogs.com/lbg280/archive/2010/01/11/1644144.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值