在 WiX 中,如何测试 Oracle ODP.Net 的注册表项(而非值)是否存在

发布于 2024-08-03 01:00:23 字数 707 浏览 5 评论 0原文

更具体地说,我想测试机器上是否安装了 Oracle ODP.Net。我想通过测试 HKLM\SOFTWARE\ORACLE\ODP.NET 注册表项来做到这一点。

ODP.Net 使用的实际值存储在 HKLM\SOFTWARE\ORACLE\ODP.NET\2.111.6.20 中,但是我假设这个较低级别密钥的名称会随着 Oracle 发布更新而更改。

我尝试了以下失败的方法,可能是因为(默认)值并不真正存在,或者可能是因为它为空(我不确定它在注册表中的具体表示方式)。

<Property Id="ORACLE_ODPNET">
  <RegistrySearch Id="ODPNET_RegKey" Type="raw" Root="HKLM" Key="SOFTWARE\ORACLE\ODP.NET" Name="(Default)"/>
</Property>
<Condition Message="This setup requires ODP.Net to be installed.">
  Installed OR ORACLE_ODPNET
</Condition>

因此,以下任何内容都会对我有所帮助:

  • 一种搜索注册表项的方法 其下没有任何值。
  • 搜索注册表值的方法 使用包含通配符的路径
  • 测试 ODP.Net 的更好方法 正在安装

More specifically I want to test whether Oracle ODP.Net is installed on a machine. I want to do this by testing for the HKLM\SOFTWARE\ORACLE\ODP.NET registry key.

The actual values used by ODP.Net are stored in HKLM\SOFTWARE\ORACLE\ODP.NET\2.111.6.20 however I assume that this lower level key's name will change as updates are released by Oracle.

I have tried the following which fails, possibly because the (Default) value doesn't really exist or possibly because it is null (I'm not sure exactly how it's represented in the registry).

<Property Id="ORACLE_ODPNET">
  <RegistrySearch Id="ODPNET_RegKey" Type="raw" Root="HKLM" Key="SOFTWARE\ORACLE\ODP.NET" Name="(Default)"/>
</Property>
<Condition Message="This setup requires ODP.Net to be installed.">
  Installed OR ORACLE_ODPNET
</Condition>

So any of the following would be helpful to me:

  • A way to search for a registry key
    with no values under it.
  • A way to search for a registry value
    using a path containing wildcards
  • A better way to test for ODP.Net
    being installed

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

[旋木] 2024-08-10 01:00:23

好的,根据 Sascha 的信息,答案似乎是“你不能”使用内置的 WiX 注册表功能。

现在我还希望这个测试与其他启动条件测试一起进行,这使得它变得有点困难。让它发挥作用花了我相当长的时间,尽管现在我知道如何做到这一点相当简单,所以希望这能减轻其他人同样的痛苦。

首先在 WiX 产品中创建一个属性:

<Property Id="ODPNETINSTALLED">0</Property>

接下来创建一个自定义操作来检查密钥,并将 ODPNETINSTALLED 设置为“1”(如果存在)。我不打算在此处编译自定义操作并将其添加到安装程序,但如果您在 Visual Studio 中使用 Votive,则相当简单。我的自定义操作的代码是:

using Microsoft.Deployment.WindowsInstaller;
using Microsoft.Win32;

namespace WiXCustomAction
{
  public class CustomActions
  {
    [CustomAction]
    public static ActionResult CheckOdpNetInstalled(Session xiSession)
    {
      xiSession.Log("Begin CheckOdpNetInstalled");

      RegistryKey lKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ORACLE\ODP.Net");

      xiSession["ODPNETINSTALLED"] = lKey == null ? "0" : "1";

      return ActionResult.Success;
    }
  }
}

现在您需要注册并安排操作,因为我希望警告与其他启动条件一起出现,所以我必须将其添加到 InstallUISequence 元素中:

<Binary Id="WiXCustomAction.dll" SourceFile="$(var.WiXCustomAction.TargetDir)$(var.WiXCustomAction.TargetName).CA.dll" />
<CustomAction Id="CheckOdpNet" BinaryKey="WiXCustomAction.dll" DllEntry="CheckOdpNetInstalled" Execute="immediate" />
<InstallUISequence>
  <Custom Action="CheckOdpNet" Before="LaunchConditions">NOT Installed</Custom>
</InstallUISequence>

最后添加启动条件来检查属性:

<Condition Message="!(loc.OracleOdpCondition)">
  Installed OR ODPNETINSTALLED="1"
</Condition>

请注意,我相信 InstallUISequence 中的调度意味着在非 UI 安装期间不会触发自定义操作。但是,我的安装程序必须安装 UI,所以这对我来说不是问题。

OK, so thanks to Sascha's information it seems that the answer is "you can't" using the built-in WiX registry functions.

Now I also wanted this test to happen along with the other launch condition tests which makes it a bit harder. Getting this to work has taken me quite a while although it's fairly simple now I know how, so hopefully this will save someone else the same pain.

First create a property inside your WiX Product:

<Property Id="ODPNETINSTALLED">0</Property>

Next create a custom action to check for the key and set ODPNETINSTALLED to "1" if it exists. I'm not going to go into compiling and adding the custom action to the installer here but it's fairly simple if you use Votive in Visual Studio. The code for my custom action is:

using Microsoft.Deployment.WindowsInstaller;
using Microsoft.Win32;

namespace WiXCustomAction
{
  public class CustomActions
  {
    [CustomAction]
    public static ActionResult CheckOdpNetInstalled(Session xiSession)
    {
      xiSession.Log("Begin CheckOdpNetInstalled");

      RegistryKey lKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ORACLE\ODP.Net");

      xiSession["ODPNETINSTALLED"] = lKey == null ? "0" : "1";

      return ActionResult.Success;
    }
  }
}

Now you need to register and schedule the action, because I wanted the warning to appear along with my other launch conditions I had to add it to the InstallUISequence element:

<Binary Id="WiXCustomAction.dll" SourceFile="$(var.WiXCustomAction.TargetDir)$(var.WiXCustomAction.TargetName).CA.dll" />
<CustomAction Id="CheckOdpNet" BinaryKey="WiXCustomAction.dll" DllEntry="CheckOdpNetInstalled" Execute="immediate" />
<InstallUISequence>
  <Custom Action="CheckOdpNet" Before="LaunchConditions">NOT Installed</Custom>
</InstallUISequence>

Finally add a launch condition to check the property:

<Condition Message="!(loc.OracleOdpCondition)">
  Installed OR ODPNETINSTALLED="1"
</Condition>

Note that I believe that scheduling in InstallUISequence means the custom action won't be fired during non-UI installs. However, my installer must have UI install so it's not an issue for me.

雪落纷纷 2024-08-10 01:00:23

只需省略RegistrySearch/@Name即可获取“(默认)”值。不幸的是,我不知道如何进行递归搜索,您将需要选择一个“已知”注册表项,该注册表项将在版本之间保持稳定,并以此为基础进行搜索。

<Property Id="ORACLE_ODPNET">
  <RegistrySearch Id="ODPNET_RegKey" Type="raw" Root="HKLM" Key="SOFTWARE\ORACLE\ODP.NET" />
</Property>
<Condition Message="This setup requires ODP.Net to be installed.">
  Installed OR ORACLE_ODPNET
</Condition>

Simply omit RegistrySearch/@Name to get the "(Default)" value. Unfortunately there's no way that I'm aware of to do a recursive search, you're going to need to pick a "known" registry key that will be stable between releases and base your search from that.

<Property Id="ORACLE_ODPNET">
  <RegistrySearch Id="ODPNET_RegKey" Type="raw" Root="HKLM" Key="SOFTWARE\ORACLE\ODP.NET" />
</Property>
<Condition Message="This setup requires ODP.Net to be installed.">
  Installed OR ORACLE_ODPNET
</Condition>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文