Class: Chef::Provider::Package::Windows::RegistryUninstallEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/provider/package/windows/registry_uninstall_entry.rb

Constant Summary collapse

UNINSTALL_SUBKEY =
'Software\Microsoft\Windows\CurrentVersion\Uninstall'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hive, key, registry_data, uninstall_key = "UninstallString") ⇒ RegistryUninstallEntry

Returns a new instance of RegistryUninstallEntry.


78
79
80
81
82
83
84
85
86
87
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 78

def initialize(hive, key, registry_data, uninstall_key = "UninstallString")
  @logger = Chef::Log.with_child({ subsystem: "registry_uninstall_entry" })
  logger.trace("Creating uninstall entry for #{hive}::#{key}")
  @hive = hive
  @key = key
  @data = registry_data
  @display_name = RegistryUninstallEntry.read_registry_property(registry_data, "DisplayName")
  @display_version = RegistryUninstallEntry.read_registry_property(registry_data, "DisplayVersion")
  @uninstall_string = RegistryUninstallEntry.read_registry_property(registry_data, uninstall_key)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data


94
95
96
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 94

def data
  @data
end

#display_nameObject (readonly)

Returns the value of attribute display_name


91
92
93
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 91

def display_name
  @display_name
end

#display_versionObject (readonly)

Returns the value of attribute display_version


92
93
94
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 92

def display_version
  @display_version
end

#hiveObject (readonly)

Returns the value of attribute hive


89
90
91
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 89

def hive
  @hive
end

#keyObject (readonly)

Returns the value of attribute key


90
91
92
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 90

def key
  @key
end

#loggerObject (readonly)

Returns the value of attribute logger


95
96
97
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 95

def logger
  @logger
end

#uninstall_stringObject (readonly)

Returns the value of attribute uninstall_string


93
94
95
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 93

def uninstall_string
  @uninstall_string
end

Class Method Details

.find_entries(package_name) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 30

def self.find_entries(package_name)
  logger.trace("Finding uninstall entries for #{package_name}")
  entries = []
  [
    [::Win32::Registry::HKEY_LOCAL_MACHINE, (::Win32::Registry::Constants::KEY_READ | 0x0100)],
    [::Win32::Registry::HKEY_LOCAL_MACHINE, (::Win32::Registry::Constants::KEY_READ | 0x0200)],
    [::Win32::Registry::HKEY_CURRENT_USER],
  ].each do |hkey|
    desired = hkey.length > 1 ? hkey[1] : ::Win32::Registry::Constants::KEY_READ
    begin
      ::Win32::Registry.open(hkey[0], UNINSTALL_SUBKEY, desired) do |reg|
        reg.each_key do |key, _wtime|

          entry = reg.open(key, desired)
          display_name = read_registry_property(entry, "DisplayName")
          if display_name.to_s.rstrip == package_name
            quiet_uninstall_string = RegistryUninstallEntry.read_registry_property(entry, "QuietUninstallString")
            entries.push(quiet_uninstall_string_key?(quiet_uninstall_string, hkey, key, entry))
          end
        rescue ::Win32::Registry::Error => ex
          logger.trace("Registry error opening key '#{key}' on node #{desired}: #{ex}")

        end
      end
    rescue ::Win32::Registry::Error => ex
      logger.trace("Registry error opening hive '#{hkey[0]}' :: #{desired}: #{ex}")
    end
  end
  entries
end

.loggerObject


74
75
76
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 74

def self.logger
  Chef::Log
end

.quiet_uninstall_string_key?(quiet_uninstall_string, hkey, key, entry) ⇒ Boolean

Returns:

  • (Boolean)

61
62
63
64
65
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 61

def self.quiet_uninstall_string_key?(quiet_uninstall_string, hkey, key, entry)
  return RegistryUninstallEntry.new(hkey, key, entry) if quiet_uninstall_string.nil?

  RegistryUninstallEntry.new(hkey, key, entry, "QuietUninstallString")
end

.read_registry_property(data, property) ⇒ Object


67
68
69
70
71
72
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 67

def self.read_registry_property(data, property)
  data[property]
rescue ::Win32::Registry::Error
  logger.trace("Failure to read property '#{property}'")
  nil
end