So I found a solution myself. I had to write another function to check if the key exists in a given path before I could actually get its value.
def key_exists?(path)
begin
Win32::Registry::HKEY_LOCAL_MACHINE.open(path, ::Win32::Registry::KEY_READ)
return true
rescue
return false
end
end
and here is the modified get function:
paths.each do |path|
if key_exists?(path)
Win32::Registry::HKEY_LOCAL_MACHINE.open(path, access_type) do |reg|
reg.each_key do |key|
k = reg.open(key)
app = k['DisplayName'] rescue nil
if app == app_name
return k['UninstallString'] rescue nil
end
end
end
else
return false
end
end