使用VS2003 自带的installer 遇到奇怪的问题!高分请高手解答,很快结帖!!
小弟第一次做installer,在我的项目部署中要实现自定义安装程序时,如果检测到旧版本,弹出对话框,删除旧版本,接着安装项目!这些功能通过自定义install类的override install方法已经实现,主输出设置为自定义install类库,
但效果如下:
1.双击setup.exe-->进入vs2003 installer 默认的welcome页面--进入vs2003installer 默认的installation Folder页面-->执行安装---弹出检测到旧版本对话框--.....
问题是我要实现像金山词霸那种效果,首先就弹出检测到旧版本对话框!感觉override install 事件是在那些默认页面之后,拷贝文件执行安装之前才执行!
请问高手怎么实现如下效果啊?
1.双击setup.exe-->弹出检测到旧版本对话框--进入vs2003 installer 默认的welcome页面--进入vs2003installer 默认的installation Folder页面-->执行安装---.....
附自定义install类库
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using Microsoft.Win32;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace eGiftAutoUnInstall
{
/// <summary>
/// Summary description for AutoUnistall.
/// </summary>
[RunInstaller(true)]
public class AutoUnInstall : System.Configuration.Install.Installer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public AutoUnInstall()
{
// This call is required by the Designer.
InitializeComponent();
// TODO: Add any initialization after the InitializeComponent call
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
protected override void OnBeforeInstall(IDictionary savedState)
{
base.OnBeforeInstall (savedState);
}
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
string text1 = "System will remove the old version Bleum Calendar for you";
string text2 = "Bleum Calendar 2007";
MessageBoxButtons buttons1 = MessageBoxButtons.YesNo;
DialogResult result1 = MessageBox.Show(text1, text2, buttons1);
if (result1 == DialogResult.Yes)
{
}
else
{
base.Uninstall(stateSaver);
}
// frmOldVersion fov = new frmOldVersion();
// fov.ShowDialog();
//search for eGift.exe from zhucibiao
string uninstallpath="";
if(IsExistOldVersion(ref uninstallpath))
{
// string text1 = "System will remove the old version Bleum Calendar for you";
// string text2 = "Bleum Calendar 2007";
// MessageBoxButtons buttons1 = MessageBoxButtons.YesNo;
// DialogResult result1 = MessageBox.Show(text1, text2, buttons1);
// if (result1 == DialogResult.Yes)
// {
//
// }
//MessageBox.Show(
//new System.Collections.Specialized.ListDictionary();
//this.Uninstall(
}
}
private bool IsExistOldVersion(ref string uninstallpath)
{
string strRegPath = @"Software\\Microsoft\\Installer\\Assemblies";
//string
RegistryKey regRootKey;
RegistryKey regSubKey;
///定义Root指向注册表HKEY_LOCAL_MACHINE节点
regRootKey = Registry.CurrentUser;
regSubKey = regRootKey.OpenSubKey(strRegPath);
Regex rg = new Regex("eGift.exe");
string[] softlist = regSubKey.GetSubKeyNames();
for(int i=0 ;i<= softlist.Length;i++)
{
if(rg.IsMatch(softlist[i]))
{
uninstallpath =softlist[i];
return true;
}
}
return false;
}
private void DeleteOldVersion(string oldversion)
{
string oldversiondir="";
//Kill process
Process[] processArray1 = Process.GetProcessesByName("eGift");
if (processArray1.Length > 0)
{
for(int i=0;i<=processArray1.Length-1;i++)
{
processArray1[i].Kill();
}
}
oldversiondir = oldversion.Substring(0,oldversion.LastIndexOf("|"));
oldversiondir = oldversiondir.Replace("|","\\");
//delete file folder
if (Directory.Exists(oldversiondir))
{
if(Directory.Exists(oldversiondir+"\\"+"wallpaper"))
{
Directory.Delete(oldversiondir+"\\"+"wallpaper",true);
}
if(File.Exists(oldversion+"\\"+"App.ico"))
{
File.Delete(oldversion+"\\"+"App.ico");
}
if(File.Exists(oldversion))
{
File.Delete(oldversion);
}
}
}
}
}