之前提出过两个类似的问题,都没有得到满意的答复,http://topic.csdn.net/u/20101017/16/2bc756ba-fc36-4a8d-95ab-15831e460528.html?1689388944
和
http://topic.csdn.net/u/20101015/09/88fe5c04-61c8-4ef1-9da8-921eb69e42a9.html根据微软的帮助,制作了继承与Installer类的一个自动运行的类,如下:using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Windows.Forms;namespace StartProgram
{
[RunInstaller(true)]
public partial class AutorunInstaller : System.Configuration.Install.Installer
{
public AutorunInstaller()
{
InitializeComponent();
} public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
} public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
// 在安装完毕后,运行刚刚安装的程序M.exe
//MessageBox.Show("Complete-- Commit");
string myInput = Context.Parameters["CHECKBOXA1"];
bool bChecked = true;
//if (myInput == "Checked")
//{
// bChecked = true;
//}
//MessageBox.Show(myInput);
if (bChecked == true)
{
string exe_path = @"C:\Program Files\M\";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "M.exe";
process.StartInfo.WorkingDirectory = exe_path;
process.StartInfo.CreateNoWindow = true;
process.Start();
//if (process.HasExited)
//{
// MessageBox.Show("complete");
//}
}
}
现在的问题是:在弹出结束安装窗口之前的确能够起到M.exe,但是,在启动M之后安装结束窗口仍然存在,
也就是说安装程序和M同时存在了,在M打开后,还需手动去关闭安装程序的最后一个结束窗口。1)、有什么办法可以在安装程序的最后一个窗口关闭之后再打开M?尝试放在
protected virtual void OnAfterInstall(IDictionary savedState);
里启动,但是好像根本没反应,似乎没有执行到这里一样,
2)、不知为什么?
和
http://topic.csdn.net/u/20101015/09/88fe5c04-61c8-4ef1-9da8-921eb69e42a9.html根据微软的帮助,制作了继承与Installer类的一个自动运行的类,如下:using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Windows.Forms;namespace StartProgram
{
[RunInstaller(true)]
public partial class AutorunInstaller : System.Configuration.Install.Installer
{
public AutorunInstaller()
{
InitializeComponent();
} public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
} public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
// 在安装完毕后,运行刚刚安装的程序M.exe
//MessageBox.Show("Complete-- Commit");
string myInput = Context.Parameters["CHECKBOXA1"];
bool bChecked = true;
//if (myInput == "Checked")
//{
// bChecked = true;
//}
//MessageBox.Show(myInput);
if (bChecked == true)
{
string exe_path = @"C:\Program Files\M\";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "M.exe";
process.StartInfo.WorkingDirectory = exe_path;
process.StartInfo.CreateNoWindow = true;
process.Start();
//if (process.HasExited)
//{
// MessageBox.Show("complete");
//}
}
}
现在的问题是:在弹出结束安装窗口之前的确能够起到M.exe,但是,在启动M之后安装结束窗口仍然存在,
也就是说安装程序和M同时存在了,在M打开后,还需手动去关闭安装程序的最后一个结束窗口。1)、有什么办法可以在安装程序的最后一个窗口关闭之后再打开M?尝试放在
protected virtual void OnAfterInstall(IDictionary savedState);
里启动,但是好像根本没反应,似乎没有执行到这里一样,
2)、不知为什么?
解决方案 »
- 一个C# dataGridView的问题
- 如何快速显示二进制读入的数据呢?(可能描述有错)
- 关于Asp.net调用activeX控件问题
- 数据库连接异常:System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.
- 怎么删除 richtextbox中的字符串
- 初学者,求学经过!`
- 如何设置可以使得DataGrid(WinForm)中的一些单元格是只读状态?
- 关于.net中的SQLSERVER数据库问题
- datagridtextboxcolumn中,headertext的样式怎么设置?可不可以限定某一列是只读的??
- WCF断线重连后服务端如何清理会话
- 100分 XML绑定到datagridview,给源码的分全给他
- C#有啥好书啊!
public override void Install(System.Collections.IDictionary stateSaver)
{//重写install方法
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
string setuppath=asm.Location;//获取程序路径
if( System.IO.File.Exists(setuppath))
System.Diagnostics.Process.Start(setuppath);//启动程序
}
然后, 在你建立的打包项目中,在custom action(自定义操作)中的安装上点右键新建,选择你的启动程序,应该就可以了。
放心吧,wix是完全免费的,它是微软根据windows installer使用c#开发的一个打包工具,完全兼容vs
windows installer本身就带有启动应用程序的Action,完全不用再写Action来实现的,但是vs自带的打包应该很难实现这种效果;如果自己写Action也不容易实现,因为所有的Action(包括自定义的Action)都包含在InstallExecuteSequence或者InstallUISequence序列中,这些序列都在ExitDialog(结束界面)调用之前就执行完了,所以要在最后执行程序,我们必须把Action绑定到完成按钮的事件上,使用wix或者直接编辑msi可以达到这种效果,下面是直接编辑msi实现方法:1、首先下载orca,它是msi数据库编辑工具。
2、使用orca打开msi文件,在Tables列表中找到CustomAction表,添加新行如下:
Action Type Source...
LaunchFile 210 FoobarEXE
Source字段值就是你执行文件的名称,它是File表的外键,必须跟File表中File列的值对应
3、找到ControlEvent表,添加新行:
Dialog Control Event Argument Condition Order
...
ExitDialog Finish DoAction LaunchFile 1 2
4、保存修改后的msi文件,就大功告成了,此方式已测试,绝对可行
Dialog Control Event Argument Condition Order
...
FinishedForm CloseButton DoAction LaunchFile 1 2以上是用vs打包后测试通过
弄一个checkbox,Text就是 安装结束启动程序
打钩的话 安装完毕点关闭 就启动程序啊 这样不就可以了
而且根本无法发现你说的orca(用来打开msi的工具)
我的是winxp
多谢你,现在在FinishedForm 中点击CloseButton后是可以打开安装的程序,但是,FinishedForm自己关闭不了?不知道该怎么关闭?
奇怪,我这里都可以关掉的……确定一下ControlEvent表的记录,Dialog字段值为FinishedForm的记录应该有两条,其中一条的Event值是EndDialog,也就是关闭窗口,另一条就是我们添加的Event值是DoActionFinishedForm CloseButton EndDialog Return 1 0
FinishedForm CloseButton DoAction LaunchFile 1 2
FinishedForm CloseButton EndDialog Return 1 0
为
FinishedForm CloseButton DoAction LaunchFile 1 2
!!!
原来是二者并存!!现在可以了,
没办法只能这样了,你可以最终发布的时候再去改msi文件,用vs打包有它的局限性,如果使用wix就不会出现这样情况了
可能是用惯UI了,