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.


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

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


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

def data
  @data
end

#display_nameObject (readonly)

Returns the value of attribute display_name


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

def display_name
  @display_name
end

#display_versionObject (readonly)

Returns the value of attribute display_version


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

def display_version
  @display_version
end

#hiveObject (readonly)

Returns the value of attribute hive


87
88
89
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 87

def hive
  @hive
end

#keyObject (readonly)

Returns the value of attribute key


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

def key
  @key
end

#loggerObject (readonly)

Returns the value of attribute logger


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

def logger
  @logger
end

#uninstall_stringObject (readonly)

Returns the value of attribute uninstall_string


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

def uninstall_string
  @uninstall_string
end

Class Method Details

.find_entries(package_name) ⇒ Object


28
29
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
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 28

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


72
73
74
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 72

def self.logger
  Chef::Log
end

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

Returns:

  • (Boolean)

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

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


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

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