在每台机器安装上删除 HKCU 下的注册表项 [英] Remove registry keys under HKCU on a per machine installation

查看:23
本文介绍了在每台机器安装上删除 HKCU 下的注册表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 WiX 3.6 构建了一个 perMachine 安装程序来安装我尚未开发的软件.不幸的是,该软件在执行过程中会在 HKCU 下创建一些注册表项.

I build a perMachine installer using WiX 3.6 to install a software I had not developed. Unfortunately the software creates some registry keys under HKCU during execution.

卸载时,还应删除自己创建的密钥.删除这些键似乎并不容易.我正在与 ICE57 和/或 ICE38战斗".两者都抱怨 perUser 和 perMachine 数据之间的混合.

On uninstall, the self created keys should also be removed. It seems not so easy to remove these keys. I am "fighting" with ICE57 and/or ICE38. Both complaining the mix between perUser and perMachine data.

希望您能为我指出解决此问题的正确方向.

Hopefully you can point me in the right direction on fixing this issue.

推荐答案

要克服 ICE,您应该将 Per-User 注册表移动到单独的组件并使用某些注册表项作为该组件的 keyPath,即:

To overcome ICEs you should move Per-User registry to separate components and use some registry entry as keyPath for that component, i.e.:

<Component Id='PerUserRegistry' Guid='*'>
  <RegistryValue Id="PerUserRegistry_KeyPAth" KeyPath="yes" Root="HKCU" Key="Software\[Manufacturer]\[ProductName]\[ProductCode]\PerUserRegistry" Name="[PackageCode]" Value="[ProductVersion]" Type="string" />
  <!--Other Per-user registry goes here-->
</Component>

我完全同意 Christopher:通常的做法是在卸载时保留每个用户的数据,但如果需要删除,则 Active Setup 是唯一真正的选择.

I completely agree with Christopher: It is common practice to leave per-user data on uninstall, but if removal is necessary, then Active Setup is the only real option.

首先我建议您在安装或重新安装而不是卸载时删除它们,您只需要添加 RemoveRegirty 条目和 Active Setup,即使用此 WiX 代码:

First I propose you to remove them on Install or Re-Install instead of uninstall, you just need add RemoveRegirty entry and Active Setup, i.e. with this WiX code:

<Component Id='ActiveSetup' Guid='*'>
  <RegistryValue Id="ActiveSetup00" Root="HKLM" KeyPath="yes" Key="SOFTWARE\SOFTWARE\Microsoft\Active Setup\Installed Components\[PackageCode]\" Name="StubPath" Value="msiexec /fup [ProductCode] /qb-!" Type="string" />
  <RegistryValue Id="ActiveSetup01" Root="HKLM" Key="SOFTWARE\SOFTWARE\Microsoft\Active Setup\Installed Components\[PackageCode]\" Value="[ProductName] [ProductVerion] Configuration" Type="string" />
</Component>
<Component Id='PerUserRegistryCleanup' Guid='*'>
  <RegistryValue Id="PerUserRegistry_KeyPath" Root="HKCU" KeyPath="yes" Key="SOFTWARE\SOFTWARE\Microsoft\Active Setup\Installed Components\[PackageCode]\" Name="StubPath" Value="msiexec /fup [ProductCode] /qb-!" Type="string" />
  <RemoveRegistryKey Id='PerUserRegCleanup' Root='HKCU' Action='removeOnInstall' Key='Key\To\Be\Removed'/>
</Component>

注意:非常推荐在 ActiveSetup 中使用 [PackageCode],因此对于 MSI 软件包的每个新版本(构建),您都添加单独的条目(另请参阅我的最后说明).我故意将每个用户的活动设置注册表用作密钥路径,因此您不会为当前用户运行它两次.

Note: [PackageCode] use in ActiveSetup is very recommended, so with each new version (build) of MSI package you add separate entry (also see my final note). I used per-user active setup registry as key-path on purpose, so you don't run it for current user twice.

至于卸载后删除它们,现在,希望您需要删除整个键,而不仅仅是一些值.在任何一种情况下,我都会创建自定义操作以在卸载期间为 Active Setup 添加注册表项(或者如果有很多这样的键/值,请创建和部署 .CMD 文件,并在卸载时启动它,在 RemoveFiles 操作之前,添加所有注册).

As for removing them after uninstall, Now, hopefully you need to remove entire key, and not just some values. In either case, I would create custom action to add Registry entry for Active Setup during uninstall (or if there are many such keys/values, create and deploy .CMD file with those and launch it on uninstall, before RemoveFiles action, to add all of them to registry).

注意:我强烈建议在安装过程中添加删除此注册表,否则您可能会在软件尚未安装时删除每个用户的值.

Note: that I would strongly recommend adding deleting this registry during install, or you might end up removing per-user values when software is yet installed.

这里是所有这些的 WiX 代码:

So here's WiX code for all of this:

<CustomAction Id="CA_UninstallRegistryCleanUp" Directory="SystemFolder" ExeCommand="REG.exe ADD &quot;HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\MySoftName_CleanUp&quot; /v StubPath /d &quot;reg add ^&quot;HKCU\Key\To\Be\Removed^&quot; /va /f&quot; /f" Return="ignore" />
<InstallExecuteSequence>
  <Custom Action='CA_UninstallRegistryCleanUp' After='RemoveRegistryValues'>REMOVE~="ALL"</Custom>
</InstallExecuteSequence>

<Component Id='RegCleanup_Remover' Guid='*'>
  <RegistryValue Id="PerUserRegistry_KeyPAth" Root="HKLM" KeyPath="yes" Key="SOFTWARE\[Manufacturer]\[ProductName]\[ProductCode]\" Name="DummyKey" Value="[ProductVersion]" Type="string" />
  <RemoveRegistryKey Id='RegCleanup_Remover' Root='HKLM' Action='removeOnInstall' Key='SOFTWARE\Microsoft\Active Setup\Installed Components\MySoftName_CleanUp'/>
</Component>

最后说明:所有这些 Active Setup 的东西只有两个小问题:在 Windows 终端服务器上要小心;一旦为当前 .MSI 的一个用户运行了活动安装程序,如果您决定重新安装相同的程序包,它将不会再次运行,除非您更改其 PackageConde 或在 ActiveSetup 注册表项下提高版本.这些是另一天的主题,如果需要澄清,请告诉我.

Final notes: There just two small issues with all this Active Setup stuff: be careful on Windows Terminal Servers; and once active setup was run for one user for current .MSI, it will not run again if you decide to reinstall same package, unless you change its PackageConde or raise version under ActiveSetup registry key. These are topics for another day, let me know if need them clarified.

并且不要忘记将上述所有组件添加到某些功能中.

And don't forget to add all of above Components to some Feature.

这篇关于在每台机器安装上删除 HKCU 下的注册表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆