在 WiX 中,如何测试 Oracle ODP.Net 的注册表项(不是值)是否存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1327203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In WiX how do I test for the existence of a registry key (not value) for Oracle ODP.Net
提问by Dan
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.
更具体地说,我想测试是否在机器上安装了 Oracle ODP.Net。我想通过测试 HKLM\SOFTWARE\ORACLE\ODP.NET 注册表项来做到这一点。
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.
ODP.Net 使用的实际值存储在 HKLM\SOFTWARE\ORACLE\ODP.NET\2.111.6.20 中,但是我假设这个较低级别的键的名称会随着 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
- 一种搜索注册表项下没有值的方法。
- 一种使用包含通配符的路径搜索注册表值的方法
- 测试 ODP.Net 安装的更好方法
采纳答案by Dan
OK, so thanks to Sascha's information it seems that the answer is "you can't" using the built-in WiX registry functions.
好的,多亏了 Sascha 的信息,答案似乎是“你不能”使用内置的 WiX 注册表功能。
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:
首先在您的 WiX 产品中创建一个属性:
<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:
接下来创建一个自定义操作来检查密钥并将 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;
}
}
}
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:
现在您需要注册和安排操作,因为我希望警告与我的其他启动条件一起出现,我必须将它添加到安装UI序列元素:
<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.
请注意,我相信 InstallUISequence 中的调度意味着在非 UI 安装期间不会触发自定义操作。但是,我的安装程序必须安装 UI,所以这对我来说不是问题。
回答by saschabeaumont
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.
只需省略 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>