简体   繁体   English

Ruby-如何从32位红宝石读取32位和64位应用程序的注册表项

[英]Ruby - how to read registry keys for 32 bit and 64 bit applications from 32 bit ruby

I am using ruby 32 bit in my application. 我在应用程序中使用ruby 32位。 I am using "win32/registry" for reading registry keys. 我正在使用“ win32 / registry”读取注册表项。

When i use 当我使用

reg = Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\app_path')
reg_typ, reg_val = reg.read('somekey')

It by default reads in path 默认情况下,它读入路径

HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\app_path HKEY_LOCAL_MACHINE \\ SOFTWARE \\ WOW6432Node \\ app_path

.

Now some of the applications are 64 bit and I want to check for 现在一些应用程序是64位的,我想检查

HKEY_LOCAL_MACHINE\\SOFTWARE\\app_path HKEY_LOCAL_MACHINE \\ SOFTWARE \\ app_path

h. H。 But, by default it always try to find under "WOW6432Node" 但是,默认情况下,它始终尝试在“ WOW6432Node”下查找

Any suggestion on what I am missing and how can i read registry for both 32 and 64 bit applications from ruby? 关于我所缺少的任何建议,以及如何从ruby中读取32位和64位应用程序的注册表?

Apparently win32/registry is not defining the KEY_WOW64_{32,64}KEY flags which are used to do that. 显然, win32/registry没有定义用于执行此操作的KEY_WOW64_{32,64}KEY标志 But since Ruby allows re-opening classes and modules you can easily add them on your own: 但是由于Ruby允许重新打开类和模块,因此您可以轻松地自己添加它们:

module Win32::Registry::Constants
  KEY_WOW64_64KEY = 0x0100
  KEY_WOW64_32KEY = 0x0200
end

To read a 64-bit key: 读取64位密钥:

reg = Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\app_path',
        Win32::Registry::KEY_READ | Win32::Registry::KEY_WOW64_64KEY)

To read a 32-bit key: 读取32位密钥:

reg = Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\app_path',
        Win32::Registry::KEY_READ | Win32::Registry::KEY_WOW64_32KEY)

You can open a feature request for that on Ruby's bug tracker (or I can do it for you if you prefer). 您可以在Ruby的错误跟踪器上打开该功能的请求(或者,如果您愿意,我也可以为您完成)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM