使用VS2003 自带的installer 遇到奇怪的问题!高分请高手解答,很快结帖!!

showmetoyou 2006-12-14 07:28:51
小弟第一次做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);
}

}



}
}
}
...全文
221 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
showmetoyou 2006-12-18
  • 打赏
  • 举报
回复
To :bigrongshu(Life is full of possibilities)
谢谢了!结贴
bigrongshu 2006-12-15
  • 打赏
  • 举报
回复
检测应该在BeforeInstall里面,不是Install里面

// Override the 'OnBeforeInstall' method.
protected override void OnBeforeInstall(IDictionary savedState)
{
base.OnBeforeInstall(savedState);

// Add steps to be done before the installation starts.
Console.WriteLine("OnBeforeInstall method of MyInstaller called");
}
bigrongshu 2006-12-15
  • 打赏
  • 举报
回复
确实OnBeforeInstall是在真正安装时才触发的,刚看了这个贴

http://www.mcse.ms/message1066083.html

建议楼主转其他安装工具解决这个问题
showmetoyou 2006-12-15
  • 打赏
  • 举报
回复
To :bigrongshu(Life is full of possibilities)
BeforeInstall我也用过,效果一样的!
因为Install,beforeInstall都是在真正安装时才触发的,自带的欢迎form,选择路径form都没有触发事件!

大家怎么看呢?
SmallMummy 2006-12-14
  • 打赏
  • 举报
回复
路过
帮顶下
believefym 2006-12-14
  • 打赏
  • 举报
回复
帮顶
zhaochong12 2006-12-14
  • 打赏
  • 举报
回复
.... 帮顶一下 ....

111,093

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧