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


71
72
73
74
75
76
77
78
79
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 71

def initialize(hive, key, registry_data, uninstall_key = "UninstallString")
  Chef::Log.debug("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


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

def data
  @data
end

#display_nameObject (readonly)

Returns the value of attribute display_name


83
84
85
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 83

def display_name
  @display_name
end

#display_versionObject (readonly)

Returns the value of attribute display_version


84
85
86
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 84

def display_version
  @display_version
end

#hiveObject (readonly)

Returns the value of attribute hive


81
82
83
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 81

def hive
  @hive
end

#keyObject (readonly)

Returns the value of attribute key


82
83
84
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 82

def key
  @key
end

#uninstall_stringObject (readonly)

Returns the value of attribute uninstall_string


85
86
87
# File 'lib/chef/provider/package/windows/registry_uninstall_entry.rb', line 85

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)
  Chef::Log.debug("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|
          begin
            entry = reg.open(key, desired)
            display_name = read_registry_property(entry, "DisplayName")
            if display_name == 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
            Chef::Log.debug("Registry error opening key '#{key}' on node #{desired}: #{ex}")
          end
        end
      end
    rescue ::Win32::Registry::Error => ex
      Chef::Log.debug("Registry error opening hive '#{hkey[0]}' :: #{desired}: #{ex}")
    end
  end
  entries
end

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


59
60
61
62
# 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


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

def self.read_registry_property(data, property)
  data[property]
rescue ::Win32::Registry::Error => ex
  Chef::Log.debug("Failure to read property '#{property}'")
  nil
end