如何从Wix托管引导程序或自定义操作中读取某些注册表项? [英] How to read certain registry key from Wix managed bootstrapper or custom action?

查看:144
本文介绍了如何从Wix托管引导程序或自定义操作中读取某些注册表项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从托管的引导程序(.NET 4.5.2)和自定义操作(尝试.NET 2.0和4.0)读取此密钥。

I am having trouble reading this key from my managed bootstrapper (.NET 4.5.2), and my custom action (tried .NET 2.0 and 4.0).

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\基于组件的服务\软件包

I尝试使用cmd作为管理员运行bootstrapper和msi。我的测试环境是Windows 7 64位。我正在使用Wix 3.11

I tried running the bootstrapper and msi using cmd as Administrator. My test environment is Windows 7 64-bit. I am using Wix 3.11

我制作了一个测试命令行应用程序,它能够访问此密钥。

I made a test command line app and it was able to access this key.

我在引导程序和自定义操作中使用的测试代码:

The testing code I used in the bootstrapper and custom action:

static RegistryKey GetHKLMKey(string registryPath) {
    var hklm64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
    var registryKey64 = hklm64.OpenSubKey(registryPath);
    if ((registryKey64?.GetValueNames().Any()).GetValueOrDefault()) {
        return registryKey64;
    }

    var hklm32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
        return hklm32.OpenSubKey(registryPath);
    }
}
...
var path = @"SOFTWARE";

foreach (var segment in @"Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages".Split('\\')) {
    path += "\\"+segment;

    var j = GetHKLMKey(path);
    Log(path + ": " + j);

    var k = Registry.LocalMachine.OpenSubKey(path);
    Log(path + ": " + k);
    if (k == null) return true;
}

测试输出

SOFTWARE\Microsoft: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft
SOFTWARE\Microsoft: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft
SOFTWARE\Microsoft\Windows: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
SOFTWARE\Microsoft\Windows: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
SOFTWARE\Microsoft\Windows\CurrentVersion: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
SOFTWARE\Microsoft\Windows\CurrentVersion: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing
SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing
SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages: 
SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages: 


推荐答案

调试托管代码自定义操作 :不太清楚是什么问题?读取不能作为自定义操作?尝试显示来自自定义操作的消息框,然后将调试器附加到运行托管代码的 rundll32.exe 进程。然后,您可以使用Visual Studio以常规的调试方式单步执行代码。这是来自高级安装程序的精彩视频,向您展示了如何执行此操作: 调试C#自定义操作

Debugging Managed Code Custom Actions: Not quite clear what the problem is? The read does not work as a custom action? Try showing a message box from the custom action and then attach the debugger to the rundll32.exe process running managed code. Then you can step through the code using Visual Studio in normal "debug fashion". Here is a nice video from Advanced Installer showing you how to do this: Debug C# Custom Actions.

注册表阅读 :具有调试能力之后,应该有可能找出引起问题的原因。

Registry Read: Once you have debugability, it should be possible to work out what the cause is of whatever problem it is that you are seeing.


  • 受抑制的异常 :也许有某种例外正在发生,您已将自定义操作的错误检查设置为 忽略退出代码

  • 位数 :最常见的问题似乎是位数(32-位与64位)-换句话说,您读错了注册表位置,但是我认为这不是您看到的问题。

  • 访问冲突? :也可能是您正在运行某些需要从GUI获得管理员权限的东西安装程序提升为管理员权限之前的顺序。这可能会引发访问权限异常。

  • Suppressed Exception: Maybe there is an exception of some sort happening and you have set the error checking for the custom action to "ignore exit code"?
  • Bitness: The most common problem seems to be "bitness" (32-bit vs 64-bit) - in other words you read the wrong registry location, but I don't think this is the problem you are seeing.
  • Access Violation?: It could also be that you are running something that requires admin rights from the GUI sequence before the setup has elevated to admin rights. That might trigger an access rights exception.

只是有些想法浮出水面。请让我们知道它是什么。

Just some ideas off the top of my head. Please let us know what it was.

这篇关于如何从Wix托管引导程序或自定义操作中读取某些注册表项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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