VS自帶的打包程式同時自動執行一個EXE或批處理命令
我做的繼承類的程式碼是這樣的,請指點
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.IO;
namespace ClassLibrary1
{
[RunInstaller(true)]
public partial class Installer1 : Installer
{
public Installer1()
{
InitializeComponent();
}
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver); //調整後,這句放在了上面
Process p = new Process();
p.StartInfo.RedirectStandardOutput = false;
// p.StartInfo.FileName = @"mybat.exe";
p.StartInfo.FileName = @"C:\Program Files\營收系統\update.bat"; //這樣只後到是能找到批處理檔案了
p.StartInfo.UseShellExecute = true;
p.Start();
p.WaitForExit();
p.Dispose();
}
}
}
用VS2005打包,如何讓主程式在安裝完成後自動啟動?
在網上找到寫這段程式碼,
protected override void OnAfterInstall(System.Collections.IDictionary savedState)
{
base.OnAfterInstall(savedState);
path = this.Context.Parameters[ "targetdir "] + "你的程式.exe ";
System.Diagnostics.Process.Start(path);
}
新增類似下面的程式碼:
- C# code
-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
namespace CustomSetup
{
[RunInstaller(true)]
publicpartialclass Installer1 : Installer
{
public Installer1()
{
InitializeComponent();
}
新增自定義操作後,安裝時未能找到.installstate檔案的問題
在新增自定義操作時,一定要在Install中也新增上輸出。可能是因為在Install階段進行.installstate檔案的建立。所以如果不在Install中新增輸出的話,就會提示找不到相應的.installstate檔案。
比如在自定義操作中重寫了Commit方法,只想在安裝結束後進行自定義操作,但是在製作安裝檔案新增自定義操作時,應該同時在Install和Commit中新增輸出。
具體操作參照
http://msdn2.microsoft.com/zh-cn/library/d9k65z2d(VS.80).aspx