WIx-“找不到注册表项"尝试查看是否存在SQL SMO值时 [英] WIx - "Registry key not found" when trying to see if a value of SQL SMO exists

查看:77
本文介绍了WIx-“找不到注册表项"尝试查看是否存在SQL SMO值时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我做过任何WiX以来已经有一段时间了,但是刚刚发现我很久以前写的一个现有Bootstrapper exe并没有真正做到我想的那样-哎呀!我见过其他人也遇到类似的问题,但我仍然不知道为什么它不起作用.

It's been a while since I've done any WiX, but just found out that a bit of an existing bootstrapper exe I wrote ages ago, isn't actually doing what I thought it was - doh !! I've seen other people with similar issues, but I still can't figure out why it's not working.

我基本上是在尝试确定是否安装了特定版本的SQL SMO,并正在此位置的注册表中进行查找:

I'm basically trying to determine if a particular version of SQL SMO is installed and am looking in the registry at this location:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Microsoft SQLServer \ SharedManagementObjects \ CurrentVersion

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SharedManagementObjects\CurrentVersion

其中有一个名为"Version"的REG_SZ密钥,其设置为13.0.1601.5之类

where there is a REG_SZ key called "Version" and it's set to something like 13.0.1601.5

下面是我的代码的模型:

Below is a mock-up of my code:

    <?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:bal="http://schemas.microsoft.com/wix/BalExtension"
     xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension"
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">

    <Bundle Name="RegReadTesterSetup" Version="1.0.0.0" Manufacturer="BigChris Inc" UpgradeCode="fcaa47db-3b55-474f-995d-2b0a0905fced">
        <BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" />

    <util:RegistrySearch Id="IsSMOInstalled"
                 Root="HKLM"
                 Key="SOFTWARE\Microsoft\Microsoft SQL Server\SharedManagementObjects\CurrentVersion\Version"
                 Value="13.0.1601.5"
                     Win64="yes"
                 Result="exists"
                     Format="raw"
                 Variable="SMOInstalled"/>

        <Chain>
      <MsiPackage SourceFile="C:\Users\chris.moxon\AppData\Local\Temporary Projects\SimpleTextFileSetup\bin\Debug\SimpleTextFileSetup.msi"
              Id="MYTEXT"
              DisplayName="Big Chris Test File"
              Visible="yes"
              InstallCondition="SMOInstalled = 0"
              SuppressSignatureVerification="yes"/>
        </Chain>
    </Bundle>
</Wix>

注意:缩进设置(Win64和格式)只是我勉强尝试使其工作的一些尝试.但是有或没有这些设置;在64位或32位计算机上运行,​​我总是得到(在存在该密钥的计算机上!):

Note : The indented settings (Win64 & Format) are just some of my clutching at straws attempts to get it to work; but with or without these settings; run on a 64bit or 32bit machine, I always get (on machine's where this key does exist !):

找不到注册表项.密钥='SOFTWARE \ Microsoft \ Microsoft SQL Server \ SharedManagementObjects \ CurrentVersion \ Version'

Registry key not found. Key = 'SOFTWARE\Microsoft\Microsoft SQL Server\SharedManagementObjects\CurrentVersion\Version'

将数字变量"SMOInstalled"设置为值0

Setting numeric variable 'SMOInstalled' to value 0

在我的日志文件中;因此最终结果是SMOInstalled变量始终设置为0,从而始终安装了SMO(或我的文本文件).

in my log file; so the end result is that the SMOInstalled variable always gets to set to 0 and thus SMO ( or my text file ) is always installed.

我很感激(或希望)我必须做些愚蠢的事-但可惜我不知道该怎么办!!

I appreciate (or hope) that I must be doing something silly - but alas I have no idea what !!

预先感谢

大克里斯.

推荐答案

这应该有效:

<util:RegistrySearch Id="IsSMOInstalled"
             Root="HKLM"
             Key="SOFTWARE\Microsoft\Microsoft SQL Server\SharedManagementObjects\CurrentVersion"
             Value="Version"
             Win64="yes"
             Result="exists"
             Variable="SMOInstalled"/>

进行 Result ="exists" 注册表搜索时,您不需要 Format ="raw" .

You shouldn't need Format="raw" when doing a Result="exists" registry search.

您遇到的问题是您混淆了注册表项中键和值的含义.密钥"是您在选择注册表位置时在regedit底部看到的路径.该值实际上是注册表项位置上的注册表值的名称.在这种情况下,所需的注册表值是键"HKLM \ SOFTWARE \ Microsoft \ Microsoft SQL Server \ SharedManagementObjects \ CurrentVersion"中的"Version",并且您会看到该值是否存在(它将SMOInstalled设置为0(不是存在)或1(存在)).

The issue you are having is that you are mixing up what a key and value represent in the registry. The "Key" is the path you see at the bottom of regedit when you pick a registry location. The value is actually the name a registry value at the registry key location. In this case the Registry Value that you want is "Version" from the key "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\SharedManagementObjects\CurrentVersion" and you are seeing if that value exists or not (which will set SMOInstalled to 0 (not exists) or 1 (exists)).

如果要获取实际的版本信息(注册表值上的数据"),则需要使用Result ="value",然后将SMOInstalled设置为注册表值的数据,或者如果定义,则未定义不存在.

If you want to get the actual version information (the "data" on the registry value) you need to use Result="value" and then SMOInstalled will be set to the data of the Registry Value or not defined if it does not exist.

要了解 Win64 ="yes" ,您需要了解64位注册表和32位注册表之间的区别.在32位计算机上,只有一个注册表,我不确定 Win64 ='yes'注册表搜索的行为.在64位计算机上,有两个注册表位置.一个用于32位进程(x86),另一个用于64位进程(x64).如果明确指定,则可以从某个位进程查看其他位的注册表位置,但是需要确保这是您要执行的操作.尝试查看注册表的64位计算机上的32位进程将其注册表项重定向到SOFTWARE \ Wow6432Node \ abc \ xyz ...,即使您仅指定了SOFTWARE \ abc \ xyz ....

To understand Win64="yes" you need to understand the difference between the 64bit registry and 32bit registry. On a 32 bit machine there is only one registry and I'm not sure how Win64='yes' registry searches behave. On a 64 bit machine there are two registry locations. One for 32-bit processes (x86) and one for 64-bit processes (x64). If explicitly specified you can view the other bitness' registry location from a certain bitness process but you need to be sure this is what you want to do. A 32 bit process on a 64bit machine that tries to look at the registry gets its registry keys redirected to SOFTWARE\Wow6432Node\abc\xyz... even though you only specified SOFTWARE\abc\xyz... .

如果您的程序可以安装32位或64位SMO,则可能必须检查两个注册表位置.这意味着要对32位注册表位置进行两次注册表搜索,而对64位位置进行一次注册表搜索.你可以像这样

If your program works with either the 32bit or 64bit SMO installed you'll likely have to check both registry locations. This would mean having two registry searches on for the 32 bit registry location and one for the 64 bit location. You can something like this

<util:RegistrySearch Id="IsSMOInstalledx86"
             Root="HKLM"
             Key="SOFTWARE\Microsoft\Microsoft SQL Server\SharedManagementObjects\CurrentVersion"
             Value="Version"
             Result="exists"                     
             Variable="SMOInstalled"/>

<util:RegistrySearch Id="IsSMOInstalledx64"
             After="IsSMOInstalledx86"
             Condition="SMOInstalled = 0 AND VersionNT64"
             Root="HKLM"
             Key="SOFTWARE\Microsoft\Microsoft SQL Server\SharedManagementObjects\CurrentVersion"
             Value="Version"
             Win64="yes"
             Result="exists"
             Variable="SMOInstalled"/>

(作为额外的陷阱,您不能在注册表条件中使用"NOT SMOInstalled",因为仅在条件中使用 PROPERTYNAME NOT PROPERTYNAME 实际上会评估该属性是否已定义,并且根本不评估该属性的值.请参见

(Just as an extra gotcha, you can't use "NOT SMOInstalled" in your registry condition because just using PROPERTYNAME or NOT PROPERTYNAME in a condition actually evaluates whether the property is defined or not and doesn't actually evaluate the value of that property at all. See here for more info, specifically under the "Properties in Expressions" header.)

这篇关于WIx-“找不到注册表项"尝试查看是否存在SQL SMO值时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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