VS 应用程序安装包制作技巧

设置安装包的“Launch Conditions”

在安装包安装前,可以对目标机器进行一些检查,如:搜索目标机器上的文件、搜索目标机器上的注册表。对目标机器的搜索设置的“Property”,在Lauch Conditions设置中的“Condition”属性中可以被利用。从而可以根据对目标机器的一些搜索检查结果,决定是否在安装之前要做的一些事情。

Lauch Conditions设置中的“InstallUrl”属性可以设置为一个Url,也可以设置为一个相对于安装包所在位置的相对文件路径。

例如,安装包安装前,要先安装某一特定的软件,就可以通过这种方式设置。

Snap2 Snap3

 Snap4

 

 

如果安装包中有自定义操作步骤,则在其类前要加“[RunInstaller(true)]”属性。

 

如果报出“错误 1001 在初始化安装时发生异常xxx”的奇怪异常,可以采用如下的解决方法:

需要修改 CUStomActionData 的传值方式,由以前的 /key="[value]" 改为  /key=“[value]\"。
例如: /sourceDir="[SourceDir]\" /InstallDir="[TARGETDIR]\" /InstallName="Monitor"
这样问题解决了。

 

安装包中如果有快捷方式的生成,则在自定义安装过程中不能删除安装目录下的任何文件,否则,点击快捷方式将会重新安装。

 

利用OSQL.EXE工具执行数据库脚本文件,解决在同一脚本文件中创建多个存储过程的问题。

Process sqlProcess = new Process();
sqlProcess.StartInfo.FileName = TargetDir + @"Binn\osql.exe";
sqlProcess.StartInfo.Arguments = string.Format(" -S {4} -U {0} -P {1} -d {2} -i \"{3}\""
    , LoginName, LoginPwd, dbName, fileFullName, ServerIP);
sqlProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
sqlProcess.Start();
sqlProcess.WaitForExit(); //等待执行

OSQL.EXE工具位于Sql的安装目录下,将其与osql.rll一起复制到应用程序的安装目录下,就可以独立运行。

 

设置自定义操作的CustomActionData:/virtualDir=[TARGETVDIR] /targetDir=[TARGETDIR]。每一个参数以反斜扛开头,多个参数以空格分开。[TARGETVDIR]表示用户输入的虚拟目录名,[TARGETDIR]表示安装的目标位置(应用程序安装到磁盘上的路径)。

 

在自定义的安装过程中开启一个进程

Process p = new Process();
p.StartInfo.FileName = this.Context.Parameters["targetDir"] + "SQLEXPR_CHS.EXE";
p.Start();
p.WaitForExit();

 

设置某个文件夹的EveryOne完全控制的权限

Process p = new Process();
p.StartInfo.FileName = "cacls.exe";
p.StartInfo.Arguments = string.Format("{0} /e /t /g EveryOne:F", path);
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
p.WaitForExit();

 

开启IIS中的Asp.net Web扩展

string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
Process p = new Process();
p.StartInfo.FileName = "cscript.exe";
p.StartInfo.Arguments = string.Format("//B //Nologo {0}\\iisext.vbs -EnExt \"ASP.NET v2.0.50727\"", path);
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
p.WaitForExit();
 

在开始菜单中加入Internet快捷方式,具体代码如下:

代码
/// <summary>
/// 创建访问安装向导页面的Internet快捷方式
/// </summary>
private void CreateInstallPageShortcut()
{
    string targetDir = this.Context.Parameters["targetDir"];
    string virtualDir = this.Context.Parameters["virtualDir"];

    StringBuilder sb = new StringBuilder();
    sb.AppendLine("[DEFAULT]");
    sb.AppendLine(string.Format("BASEURL=http://localhost/{0}/Install/Default.aspx", virtualDir));
    sb.AppendLine("[InternetShortcut]");
    sb.AppendLine(string.Format("URL=http://localhost/{0}/Install/Default.aspx", virtualDir));
    sb.AppendLine("Modified=30AE1D0B602AC70158");
    sb.AppendLine(string.Format(@"IconFile={0}ShortcutIcons\weihu.ico", targetDir));
    sb.AppendLine("IconIndex=0");
    sb.AppendLine("HotKey=0");
    sb.AppendLine("IDList=");
    sb.AppendLine("[{000214A0-0000-0000-C000-000000000047}]");
    sb.AppendLine("Prop3=19,2");
    sb.AppendLine("[InternetShortcut.A]");
    sb.AppendLine("[InternetShortcut.W]");

    WriteFile(sb.ToString(), "维护信息.url");
}

/// <summary>
/// 在开始——程序中写入文件
/// </summary>
/// <param name="content"></param>
/// <param name="fileName"></param>
private static void WriteFile(string content, string fileName)
{
    string fileFullPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "/管理系统/";
    if (!Directory.Exists(fileFullPath))
    {
        Directory.CreateDirectory(fileFullPath);
    }
    string fileFullName = fileFullPath + fileName;
    using (FileStream fs = new FileStream(fileFullName, FileMode.OpenOrCreate, FileAccess.Write))
    {
        byte[] data = new UTF8Encoding().GetBytes(content);
        fs.Write(data, 0, data.Length);
        fs.Flush();
        fs.Close();
    };
}
public override void Install(IDictionary stateSaver)
{
    base.Install(stateSaver);

     CreateInstallPageShortcut();

}

转载于:https://www.cnblogs.com/yyniuznyin/archive/2010/04/22/1718187.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值