注册表项在 Wix 中无法正常工作
Registry entry not working correctly in Wix
我正在创建一个 x64 msi。我有一些注册表值要设置。在 Wix 中,我使用以下代码。
<Component Id="RegistryEntries1" Guid="{GUID1}" Win64="yes">
<RegistryKey Root="HKLM"
Key="Software\Microsoft\Windows\CurrentVersion\Authentication\Credential Providers\{FF.....}"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Value="SomeName" KeyPath="yes"/>
</RegistryKey>
</Component>
<Component Id="RegistryEntries2" Guid="{GUID2}" Win64="yes">
<RegistryKey Root="HKCR"
Key="CLSID\{FF.....}"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Value="SomeName" KeyPath="yes"/>
</RegistryKey>
</Component>
<Component Id="RegistryEntries3" Guid="{GUID3}" Win64="yes">
<RegistryKey Root="HKCR"
Key="CLSID\{{FF.....}\InprocServer32"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Value="SomeName.dll" KeyPath="no"/>
<RegistryValue Type="string" Name="ThreadingModel" Value="Apartment" KeyPath="yes"/>
</RegistryKey>
</Component>
这些值是在注册表中设置的,但我的应用程序无法正常工作。
当我使用 reg 文件设置注册表值时,应用程序正常运行。
我的SomeName.dll在System32
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\Credential Providers\{FF.....}]
@="SomeName"
[HKEY_CLASSES_ROOT\CLSID\{FF.....}]
@="SomeName"
[HKEY_CLASSES_ROOT\CLSID\{FF.....}\InprocServer32]
@="SomeName.dll"
"ThreadingModel"="Apartment"
我的Wix代码有问题吗?
问题很可能是 HKCR 是一个虚拟键,在您的情况下是 HKLM\Software\Classes 和 HKCU\Software\Classes 的合并视图。这解释了它:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724475(v=vs.85).aspx
所以 运行 本地系统帐户看不到这些。如果您要 运行 使用系统帐户进行 regedit,如果发生这种情况,您将看不到您的 HKCR 类。
因此,如果您在 HKLM\Software\Classes 处输入条目,我认为您的 service/service 安装程序代码会看到它们。 ServiceInstaller 类 通常 运行 作为系统帐户的自定义操作。如果您使用的是 WiX,则不需要 ServiceInstaller 类(也许您是从 Visual Studio 设置迁移过来的),因为 ServiceInstall 和 ServiceControl 将完成这项工作。
我正在创建一个 x64 msi。我有一些注册表值要设置。在 Wix 中,我使用以下代码。
<Component Id="RegistryEntries1" Guid="{GUID1}" Win64="yes">
<RegistryKey Root="HKLM"
Key="Software\Microsoft\Windows\CurrentVersion\Authentication\Credential Providers\{FF.....}"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Value="SomeName" KeyPath="yes"/>
</RegistryKey>
</Component>
<Component Id="RegistryEntries2" Guid="{GUID2}" Win64="yes">
<RegistryKey Root="HKCR"
Key="CLSID\{FF.....}"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Value="SomeName" KeyPath="yes"/>
</RegistryKey>
</Component>
<Component Id="RegistryEntries3" Guid="{GUID3}" Win64="yes">
<RegistryKey Root="HKCR"
Key="CLSID\{{FF.....}\InprocServer32"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Value="SomeName.dll" KeyPath="no"/>
<RegistryValue Type="string" Name="ThreadingModel" Value="Apartment" KeyPath="yes"/>
</RegistryKey>
</Component>
这些值是在注册表中设置的,但我的应用程序无法正常工作。
当我使用 reg 文件设置注册表值时,应用程序正常运行。
我的SomeName.dll在System32
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\Credential Providers\{FF.....}]
@="SomeName"
[HKEY_CLASSES_ROOT\CLSID\{FF.....}]
@="SomeName"
[HKEY_CLASSES_ROOT\CLSID\{FF.....}\InprocServer32]
@="SomeName.dll"
"ThreadingModel"="Apartment"
我的Wix代码有问题吗?
问题很可能是 HKCR 是一个虚拟键,在您的情况下是 HKLM\Software\Classes 和 HKCU\Software\Classes 的合并视图。这解释了它:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724475(v=vs.85).aspx
所以 运行 本地系统帐户看不到这些。如果您要 运行 使用系统帐户进行 regedit,如果发生这种情况,您将看不到您的 HKCR 类。
因此,如果您在 HKLM\Software\Classes 处输入条目,我认为您的 service/service 安装程序代码会看到它们。 ServiceInstaller 类 通常 运行 作为系统帐户的自定义操作。如果您使用的是 WiX,则不需要 ServiceInstaller 类(也许您是从 Visual Studio 设置迁移过来的),因为 ServiceInstall 和 ServiceControl 将完成这项工作。