【发布时间】:2021-11-19 07:06:03
【问题描述】:
我正在编写一个位于顶部的 .wxs 文件
<Product Id="*" Name="My Fancy Product" Language="1033" Version="$(var.ProductVersion)" Manufacturer="My Company, Inc." UpgradeCode="AAA79BAB-B246-4326-B875-024022F393C6">
<Package InstallerVersion="500" Compressed="yes" InstallPrivileges="limited" InstallScope="perUser" />
我需要根据特定条件将InstallPrivileges从limited更改为elevated。 (我还需要为InstallScope 做类似的事情)。
我写了一个 C# 自定义动作:
public static ActionResult SetElevated(Session session)
{
// Change InstallPrivileges to "elevated"
session.Log($"Privileged = {session["Privileged"]}");
session["Privileged"] = "1";
session.Log($"{session["Privileged"]}"); // prints "1"
session.Log($"ALLUSERS = {session["ALLUSERS"]}");
session["ALLUSERS"] = "1";
session.Log($"{session["ALLUSERS"]}"); // prints "1"
return ActionResult.Success;
}
自定义操作已安排:
<InstallUISequence>
<Custom Action="SetElevatedCustomAction" Before="MyWelcomeDlg"></Custom>
...
</InstallUISequence>
<CustomAction Id="SetElevatedCustomAction" BinaryKey="SetupCustomActionBinary" DllEntry="SetElevated" Execute="immediate" Return="check" />
但安装程序没有给出 UAC 提示。
我使用Orca 导出编译后的 MSI 中的所有表,并将其与使用InstallPrivileges="elevated" 生成的 MSI 进行比较,唯一的区别是 ALLUSERS 属性,我在自定义中将其设置为相同的值行动。
我的猜测是 ALLUSERS 不能从自定义操作中更改?那么如何动态地完成改变呢?谢谢。
【问题讨论】:
标签: wix windows-installer elevated-privileges