将 MSI 属性 写入通过 WiX 自定义操作创建的注册表
Writing MSI property to registry created through WiX custom action
我希望我使用 WiX 创建的 MSI 安装程序 运行 一个创建和加密安装程序 属性(日期)的自定义操作,然后将其写入注册表键值(进入 HKLM)。我遇到的问题是 属性 在写入注册表时未更新(由于 属性 在自定义操作中创建,因此写入空字符串)。我认为这与执行自定义操作的顺序有关,但我尝试将序列链中的自定义操作移至更早的阶段(序列为 99),但没有奏效。我想注意日志文件显示 属性 正在更新
wix .wxs 的当前设置
<InstallExecuteSequence>
<Custom Action="CustomActionTest" Before="WriteRegistryValues"/>
</InstallExecuteSequence>
<Fragment>
<Binary Id="CustomActionBinary" SourceFile="..\CustomActionTest.CA.dll"/>
<CustomAction Id="CustomActionTest" BinaryKey="CustomActionBinary" DllEntry="CustomAction1" Execute="firstSequence" Return="check"/>
</Fragment>
<Component Id="CMP_WriteToLicenseRegistry" Guid="{}" Permanent="yes">
<RegistryKey Root="HKLM" Key="SOFTWARE\Test">
<RegistryValue Action="write" Name="TestDate" Type="string" Value="[TestDateRegistryValue]"/>
</RegistryKey>
</Component>
CustomActionTest.CA.dll
中的自定义操作
[CustomAction]
public static ActionResult CustomAction1(Session session) {
session.Log("VALUE BEFORE " + session["TestDateRegistryValue"]);
session.Log("Begin CustomAction1");
session["TestDateRegistryValue"] = DateTime.Now;
session.Log("VALUE AFTER " + session["TestDateRegistryValue"]);
session.Log("End CustomAction1");
return ActionResult.Success;
}
自定义操作在第一个序列中 运行ning 并且作为即时(默认类型)操作。这意味着它将在 msi 安装程序的 'client' 阶段 运行。
WriteRegistryValues 操作在服务器阶段 运行 并且只能访问此阶段可用的属性。这包括来自 msi 数据库本身的属性的默认值和任何标记为安全的 public 属性。
要使您的 属性 值在服务器阶段可用,您必须将其标记为 Secure='yes'
。要将 属性 标记为安全,它还必须是 public 属性,这意味着它需要全大写名称。
因此,如果您将 属性 更新为
,您应该能够正确设置您的注册表值
<Property Name="TESTDATEREGISTRYVALUE" Secure="yes">
并更新自定义操作中的名称,<RegistryValue>
。
我希望我使用 WiX 创建的 MSI 安装程序 运行 一个创建和加密安装程序 属性(日期)的自定义操作,然后将其写入注册表键值(进入 HKLM)。我遇到的问题是 属性 在写入注册表时未更新(由于 属性 在自定义操作中创建,因此写入空字符串)。我认为这与执行自定义操作的顺序有关,但我尝试将序列链中的自定义操作移至更早的阶段(序列为 99),但没有奏效。我想注意日志文件显示 属性 正在更新
wix .wxs 的当前设置
<InstallExecuteSequence>
<Custom Action="CustomActionTest" Before="WriteRegistryValues"/>
</InstallExecuteSequence>
<Fragment>
<Binary Id="CustomActionBinary" SourceFile="..\CustomActionTest.CA.dll"/>
<CustomAction Id="CustomActionTest" BinaryKey="CustomActionBinary" DllEntry="CustomAction1" Execute="firstSequence" Return="check"/>
</Fragment>
<Component Id="CMP_WriteToLicenseRegistry" Guid="{}" Permanent="yes">
<RegistryKey Root="HKLM" Key="SOFTWARE\Test">
<RegistryValue Action="write" Name="TestDate" Type="string" Value="[TestDateRegistryValue]"/>
</RegistryKey>
</Component>
CustomActionTest.CA.dll
中的自定义操作 [CustomAction]
public static ActionResult CustomAction1(Session session) {
session.Log("VALUE BEFORE " + session["TestDateRegistryValue"]);
session.Log("Begin CustomAction1");
session["TestDateRegistryValue"] = DateTime.Now;
session.Log("VALUE AFTER " + session["TestDateRegistryValue"]);
session.Log("End CustomAction1");
return ActionResult.Success;
}
自定义操作在第一个序列中 运行ning 并且作为即时(默认类型)操作。这意味着它将在 msi 安装程序的 'client' 阶段 运行。
WriteRegistryValues 操作在服务器阶段 运行 并且只能访问此阶段可用的属性。这包括来自 msi 数据库本身的属性的默认值和任何标记为安全的 public 属性。
要使您的 属性 值在服务器阶段可用,您必须将其标记为 Secure='yes'
。要将 属性 标记为安全,它还必须是 public 属性,这意味着它需要全大写名称。
因此,如果您将 属性 更新为
,您应该能够正确设置您的注册表值<Property Name="TESTDATEREGISTRYVALUE" Secure="yes">
并更新自定义操作中的名称,<RegistryValue>
。