summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Dibowitz <phil@ipom.com>2021-02-03 16:17:23 -0800
committerPhil Dibowitz <phil@ipom.com>2021-02-03 16:21:35 -0800
commita16c8a7aa27ac4b4eefe531f7c94bc0997b1ff4c (patch)
treececb7d6429a94c5a0db46c5fb9875dba760f533c
parentb687c788c069f70897e4f8ef3a5baf460dc5233f (diff)
downloadohai-a16c8a7aa27ac4b4eefe531f7c94bc0997b1ff4c.tar.gz
Update `packages` for Windows to be complete.
Per the [docs](https://docs.chef.io/resources/windows_package/), there are three locations packages can be registered, but we only look in 2, this adds all 3. Now packages show up that were otherwise missing. Signed-off-by: Phil Dibowitz <phil@ipom.com>
-rw-r--r--lib/ohai/plugins/packages.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/ohai/plugins/packages.rb b/lib/ohai/plugins/packages.rb
index e9ce2b3d..33591792 100644
--- a/lib/ohai/plugins/packages.rb
+++ b/lib/ohai/plugins/packages.rb
@@ -106,7 +106,7 @@ Ohai.plugin(:Packages) do
end
end
- def collect_programs_from_registry_key(key_path)
+ def collect_programs_from_registry_key(repo, key_path)
# from http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx
if ::RbConfig::CONFIG["target_cpu"] == "i386"
reg_type = Win32::Registry::KEY_READ | 0x100
@@ -115,7 +115,7 @@ Ohai.plugin(:Packages) do
else
reg_type = Win32::Registry::KEY_READ
end
- Win32::Registry::HKEY_LOCAL_MACHINE.open(key_path, reg_type) do |reg|
+ repo.open(key_path, reg_type) do |reg|
reg.each_key do |key, _wtime|
pkg = reg.open(key)
name = pkg["DisplayName"] rescue nil
@@ -133,9 +133,10 @@ Ohai.plugin(:Packages) do
collect_data(:windows) do
require "win32/registry" unless defined?(Win32::Registry)
packages Mash.new
- collect_programs_from_registry_key('Software\Microsoft\Windows\CurrentVersion\Uninstall')
+ collect_programs_from_registry_key(Win32::Registry::HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall')
+ collect_programs_from_registry_key(Win32::Registry::HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall')
+ collect_programs_from_registry_key(Win32::Registry::HKEY_LOCAL_MACHINE, 'Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
# on 64 bit systems, 32 bit programs are stored here
- collect_programs_from_registry_key('Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
end
collect_data(:aix) do