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

编程入门 行业动态 更新时间:2024-10-27 06:24:29
本文介绍了如何从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托管引导程序或自定义操作中读取某些注册表项?

本文发布于:2023-11-03 14:34:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555373.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   注册表   操作   程序   Wix

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!