diff options
author | Hiroshi SHIBATA <[email protected]> | 2025-02-04 17:32:51 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2025-02-05 07:36:59 +0900 |
commit | 4b5bcba2e28b367f851bd21fbcd828f5e21a2f43 (patch) | |
tree | f950108ca83f46c3f7e8f05adde53210a0ba41cf | |
parent | 333bc26d82370e2f5d324c1a24e7885fde4b9657 (diff) |
Integrate read_s and read_s_expand with get_item_property for Win32::Registry
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12616
-rw-r--r-- | ext/win32/lib/win32/resolv.rb | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/ext/win32/lib/win32/resolv.rb b/ext/win32/lib/win32/resolv.rb index 0ea09ba82e..aaa9891456 100644 --- a/ext/win32/lib/win32/resolv.rb +++ b/ext/win32/lib/win32/resolv.rb @@ -67,15 +67,7 @@ module Win32 class << self private def get_hosts_dir - if defined?(Win32::Registry) - Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg| - reg.read_s_expand('DataBasePath') - end - else - cmd = "Get-ItemProperty -Path 'HKLM:\\#{TCPIP_NT}' -Name 'DataBasePath' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty DataBasePath" - output, _ = Open3.capture2('powershell', '-Command', cmd) - output.strip - end + get_item_property(TCPIP_NT, 'DataBasePath', expand: true) end def get_info @@ -134,10 +126,10 @@ module Win32 [ search.uniq, nameserver.uniq ] end - def get_item_property(path, name) + def get_item_property(path, name, expand: false) if defined?(Win32::Registry) Registry::HKEY_LOCAL_MACHINE.open(path) do |reg| - reg.read_s(key) + expand ? reg.read_s_expand(name) : reg.read_s(name) rescue Registry::Error "" end |