当我运行安装程序时,出现以下问题。
我正在执行一些需要访问注册表的自定义操作,我只能认为这是因为 WiX 配置不会使其请求管理员权限。我看过一些关于 SO 的帖子并尝试使用。
InstallPriveleges="elevated"
在包元素中,但这不会使安装程序具有管理屏蔽,也不会请求它,因此仍然会产生错误。
有关测试项目的额外信息。
我的应用程序的名称是:WindowsFormsApplication33,自定义操作项目的名称是 CustomAction1,安装项目的名称是 SetupProject1。
这是我当前的 wix xml 文件。
<Package InstallerVersion="200" Compressed="yes" InstallPrivileges="elevated" InstallScope="perUser" />
<Binary Id="CustomAction1.CA.dll" SourceFile ="..\CustomAction1\bin\$(var.Configuration)\CustomAction1.CA.dll" />
<CustomAction Id="disableTaskManager"
Return="check"
Execute="immediate"
BinaryKey="CustomAction1.CA.dll"
DllEntry="disableTaskManager" />
<CustomAction Id="enableTaskManager"
Return="check"
Execute="immediate"
BinaryKey="CustomAction1.CA.dll"
DllEntry="enableTaskManager" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="SetupProject1" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<InstallExecuteSequence>
<Custom Action="disableTaskManager" Before="InstallFinalize" />
<Custom Action="enableTaskManager" After="InstallInitialize"><![CDATA[(NOT UPGRADINGPRODUCTCODE)]]></Custom>
</InstallExecuteSequence>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Form Test Application" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Guid="{EDA315F6-A115-4348-8607-981C252EA317}">
<File Source="$(var.WindowsFormsApplication33.TargetPath)" KeyPath ="yes" />
</Component>
<Component Guid="{E3182F61-F563-4C13-82B5-8CC39D9DB380}">
<File Source="$(var.CustomAction1.TargetPath)" KeyPath ="yes" />
</Component>
<Component Guid="{E4AF325E-B244-47F5-855A-5B40DBC425D2}">
<File Source="..\WindowsFormsApplication33\bin\Release\WindowsFormsApplication33.exe.config" KeyPath="yes" />
</Component>
</ComponentGroup>
</Fragment>
更新:将 InstallScope 值从 perUser 更改为“perMachine”确实会发出 UAC 提示,但 DLL 错误仍然存在..
您的自定义操作是立即执行的,这意味着它不会随海拔升高而运行。必须推迟以海拔运行。它与 WiX 没有任何关系,只是即时自定义操作以用户身份运行但受到限制。
我努力摆脱 dll 错误,但我发现的另一种选择是不使用自定义操作并使用 wix 文件中的 XML 来创建注册表,然后在卸载时通过使用以下命令删除密钥:
ForceDeleteOnUninstall="yes"
您必须在
示例:
<!-- Register windows autostart registry -->
<Component Id="RegistryEntries" Guid="45C7AC46-1101-4301-83E1-D24392283A60">
<RegistryValue Type="string"
Name="FooStartup"
Value="[#FooMainApp]"
Root="HKLM"
Key="Software\Microsoft\Windows\CurrentVersion\Run"
Action="write"/>
</Component>
如发现:安装应用程序 C# 时注册表更改
我真的希望这能像对我一样帮助刚接触 WiX 的人。
在自定义操作标签中使用这三个属性。
<CustomAction ....
Execute="deferred"
Impersonate="no"
Return="ignore" />
这些字段将使自定义操作以管理员权限运行。
如果您使用 MajorUpgrade Element,这是一个很好的做法,因为它会在安装新版本之前删除旧版本。这意味着安装时应该先卸载旧版本,然后再安装新版本。
但是如果您使用升级项目和MajorUpgrade元素一起使用时可能会互相干扰。由于 MajorUpgrade 元素基本上是 Upgrade 元素的简化和改进版本,因此我建议您删除 Upgrade 元素并仅使用 MajorUpgrade 元素。
我是这样使用的:
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />