一个打包程序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,然后在自定义操作时找到此类,如下图:


 

 

 

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

 

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

posted on 2010-01-11 15:24  潇洒地走  阅读(310)  评论(0编辑  收藏  举报