diff options
author | Hiroshi SHIBATA <[email protected]> | 2025-02-04 17:10:46 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2025-02-05 07:36:59 +0900 |
commit | a487698cc789624924ef5e309ffbffcc36f754ca () | |
tree | 48cadf75aff783f2640c8a4e74aa7ba5cdbd763b /ext | |
parent | 078e723b24b6329280b83791c46f31dc284008d3 (diff) |
Use powershell for retrieving value from registry if fiddle is not available
Notes: Merged: https://.com/ruby/ruby/pull/12616
-rw-r--r-- | ext/win32/lib/win32/resolv.rb | 96 |
1 files changed, 70 insertions, 26 deletions
@@ -67,35 +67,60 @@ module Win32 class << self private def get_hosts_dir - Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg| - reg.read_s_expand('DataBasePath') end end def get_info search = nil nameserver = get_dns_server_list - slist = Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg| - reg.read_s('SearchList') - rescue Registry::Error - "" end search = slist.split(/,\s*/) unless slist.empty? if add_search = search.nil? search = [] - nvdom = Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg| - reg.read_s('NV Domain') - rescue Registry::Error - "" end unless nvdom.empty? @search = [ nvdom ] - udmnd = Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg| - reg.read_i('UseDomainNameDevolution') - rescue Registry::Error - 0 end if udmnd != 0 @@ -106,18 +131,31 @@ module Win32 end end - ifs = Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT + '\Interfaces') do |reg| - reg.keys - rescue Registry::Error - [] end ifs.each do |iface| next unless ns = %w[NameServer DhcpNameServer].find do |key| - ns = Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT + '\Interfaces' + "\\#{iface}" ) do |regif| - regif.read_s(key) - rescue Registry::Error - "" end break ns.split(/[,\s]\s*/) unless ns.empty? end @@ -126,10 +164,16 @@ module Win32 if add_search [ 'Domain', 'DhcpDomain' ].each do |key| - dom = Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT + '\Interfaces' + "\\#{iface}" ) do |regif| - regif.read_s(key) - rescue Registry::Error - "" end unless dom.empty? search.concat(dom.split(/,\s*/)) |