You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Wix Toolset创建Bootstrapper以预运行许可验证exe

用Wix Burn实现前置许可验证(不嵌入外部exe)

核心思路

Burn引导程序可在链入目标MSI前执行自定义动作,我们通过ExePackage调用外部许可验证exe,同时设置依赖条件,确保验证通过后才继续安装MSI。

具体步骤

1. 编写Burn引导项目

创建Wix Bootstrapper项目,在Bundle.wxs中配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
  <Bundle Name="你的产品名称" Version="1.0.0.0" Manufacturer="你的公司名" UpgradeCode="替换为你的GUID">
    <BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" />

    <!-- 定义外部许可验证exe,不嵌入到Burn包 -->
    <ExePackage
      Id="LicenseValidator"
      SourceFile="你的验证exe路径\LicenseValidator.exe"
      Compressed="no" <!-- 关键:不嵌入,保持独立文件 -->
      InstallCommand="/validate" <!-- 传递给exe的验证参数,按需调整 -->
      DetectCondition="LicenseValidationPassed = 1" <!-- 检测验证是否通过 -->
      Vital="yes" <!-- 验证失败则终止安装流程 -->
      />

    <!-- 目标MSI包 -->
    <MsiPackage
      Id="MainProductMSI"
      SourceFile="你的MSI路径\MainInstaller.msi"
      Vital="yes"
      InstallCondition="LicenseValidationPassed = 1" <!-- 仅验证通过才安装MSI -->
      />

    <!-- 存储验证结果的自定义变量 -->
    <Variable Name="LicenseValidationPassed" Type="numeric" Value="0" />
  </Bundle>
</Wix>

2. 调整许可验证exe的逻辑

验证exe需要在通过验证后,通过Burn的变量机制设置LicenseValidationPassed为1,示例C#代码如下:

using Microsoft.Deployment.WindowsInstaller.Bootstrapper;
using System;

class LicenseValidator
{
    static void Main(string[] args)
    {
        // 替换为你的实际许可密钥验证逻辑(比如弹出输入框验证)
        bool isValid = CheckUserLicense();

        if (isValid)
        {
            // 通知Burn验证通过
            Bootstrapper.Engine.SetVariableString("LicenseValidationPassed", "1");
            Environment.Exit(0); // 返回成功退出码
        }
        else
        {
            Environment.Exit(1); // 返回失败退出码,Burn会终止安装
        }
    }

    private static bool CheckUserLicense()
    {
        // 这里写你的验证逻辑,示例默认返回true
        return true;
    }
}

注意:需要引用Wix安装目录下的Microsoft.Deployment.WindowsInstaller.dll和Microsoft.Deployment.WindowsInstaller.Bootstrapper.dll。

3. 部署要求

  • 将Burn生成的引导程序(.exe)与许可验证exe放在同一目录下发给用户
  • 引导用户运行Burn程序,而非直接运行MSI

关键注意点

  • Compressed="no"确保验证exe不被嵌入Burn包,保持独立
  • Vital="yes"保证验证失败时整个安装流程终止
  • InstallCondition限制MSI仅在验证通过后安装

内容的提问来源于stack exchange,提问作者zombie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 22:31:14