如何从Wix托管引导程序或自定义操作中读取某些注册表项?

时间:2018-09-04 23:14:22

标签: wix windows-installer custom-action

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

IndexSet(unsignedInt: -1) //Negative integer '-1' overflows when stored into unsigned type 'UInt'

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

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

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

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

测试输出

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;
}

1 个答案:

答案 0 :(得分:2)

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

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

  • 受抑制的异常 :可能正在发生某种例外,并且您已将自定义操作的错误检查设置为“ < strong> ignore exit code ”?
  • 位数 :最常见的问题似乎是"bitness" (32-bit vs 64-bit)-换句话说,您读错了注册表位置,但是我认为这不是您遇到的问题。
  • 访问冲突? :也可能是您正在运行某些操作,该操作需要GUI序列中的管理员权限,然后才能将设置提升为管理员权限。这可能会触发访问权限异常。

只有一些想法浮现在脑海。请让我们知道它是什么。