从二进制文件启动EXE

时间:2012-11-20 10:30:50

标签: wix

您好我有这两个二进制文件:

<Binary Id="Sentinel" SourceFile="sentinel_setup.exe"/>
<Binary Id="Hasp" SourceFile="HASPUserSetup.exe"/>

我想按下这样的按钮启动它们:

<CustomAction Id="LaunchHasp" BinaryKey="Hasp" ExeCommand="" Return="asyncWait" />
<CustomAction Id="LaunchSentinel" BinaryKey="Sentinel" ExeCommand="" Return="asyncWait"/>

<Publish Event="DoAction" Value="LaunchHasp">1</Publish>

但是它不起作用,它只有在我从命令行以提升的权限运行安装程序时才有效。我究竟做错了什么?感谢

或者有人可以告诉我如何使用c ++自定义操作从二进制表中提取文件,因为我无法使其工作.. :(

1 个答案:

答案 0 :(得分:3)

立即自定义操作没有提升权限。您应该使用自定义操作来满足此类需求。应该改变任何改变预测环境的行动。有关详细信息,请阅读以下文章:http://bonemanblog.blogspot.com/2005/10/custom-action-tutorial-part-i-custom.html

<CustomAction Id="LaunchHasp" Impersonate="no" Execute="deferred" BinaryKey="Hasp" ExeCommand="" Return="asyncWait" />

虽然在安装阶段会执行自定义的自定义操作,但不会在按钮单击时执行。修改安装程序逻辑。据我所知,您的exe文件“sentinel_setup.exe”会更改系统,因此应在InstallExecuteSequence

中的InstallInitialize和InstallFinalize事件之间进行安排。

我建议添加一个复选框,该用户应标记为安装“Hasp”(或用户应在功能树中选择的安装程序功能)。并在此复选框状态下添加带有条件的自定义自定义操作。

有时,确实需要在安装程序UI序列期间或之前启动管理操作。在这种情况下,您需要创建一个安装引导程序,它要求提升权限并在运行MSI进程之前执行必需的操作。要请求权限,您需要将应用程序清单添加到引导程序项目中。我的引导程序很简单,但在许多情况下都可以工作。它是Windows应用程序(虽然没有任何Windows窗体 - 它允许隐藏控制台窗口),它只包含图标,应用程序清单和小代码文件:

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SetupBootstrapper
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            var currentDir = AppDomain.CurrentDomain.BaseDirectory;
            var parameters = string.Empty;
            if (args.Length > 0)
            {
                var sb = new StringBuilder();
                foreach (var arg in args)
                {
                    if (arg != "/i" && arg != "/x" && arg != "/u")
                    {
                        sb.Append(" ");
                        sb.Append(arg);
                    }
                }
                parameters = sb.ToString();
            }

            bool isUninstall = args.Contains("/x") || args.Contains("/u");

            string msiPath = Path.Combine(currentDir, "MyMsiName.msi");

            if(!File.Exists(msiPath))
            {
                MessageBox.Show(string.Format("File '{0}' doesn't exist", msiPath), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string installerParameters = (isUninstall ? "/x" : "/i ") + "\"" + msiPath + "\"" + parameters;

            var installerProcess = new Process { StartInfo = new ProcessStartInfo("msiexec", installerParameters) { Verb = "runas" } };

            installerProcess.Start();
            installerProcess.WaitForExit();
        }
    }
}