Skip to content

Commit

Permalink
Integrate read_s and read_s_expand with get_item_property for Win32::…
Browse files Browse the repository at this point in the history
…Registry
  • Loading branch information
hsbt committed Feb 5, 2025
1 parent 720e250 commit ff97184
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions ext/win32/resolv/lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,7 @@ def read_s(key)
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
Expand Down Expand Up @@ -134,10 +126,10 @@ def get_info
[ 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
Expand Down

0 comments on commit ff97184

Please sign in to comment.