Class: Inspec::Resources::WindowsPkg
- Inherits:
-
PkgManagement
- Object
- PkgManagement
- Inspec::Resources::WindowsPkg
- Defined in:
- lib/resources/package.rb
Overview
Determines the installed packages on Windows using the Windows package registry entries. @see: blogs.technet.com/b/heyscriptingguy/archive/2013/11/15/use-powershell-to-find-installed-software.aspx
Instance Attribute Summary
Attributes inherited from PkgManagement
Instance Method Summary collapse
Methods inherited from PkgManagement
#initialize, #missing_requirements
Constructor Details
This class inherits a constructor from Inspec::Resources::PkgManagement
Instance Method Details
#info(package_name) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/resources/package.rb', line 238 def info(package_name) search_paths = [ 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*', ] # add 64 bit search paths if inspec.os.arch == 'x86_64' search_paths << 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' search_paths << 'HKCU:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' end # Find the package cmd = inspec.command " Get-ItemProperty (@(\"\#{search_paths.join('\", \"')}\") | Where-Object { Test-Path $_ }) |\n Where-Object { $_.DisplayName -like \"\#{package_name}\" -or $_.PSChildName -like \"\#{package_name}\" } |\n Select-Object -Property DisplayName,DisplayVersion | ConvertTo-Json\n EOF\n\n begin\n package = JSON.parse(cmd.stdout)\n rescue JSON::ParserError => _e\n return nil\n end\n\n # What if we match multiple packages? just pick the first one for now.\n package = package[0] if package.is_a?(Array)\n\n {\n name: package['DisplayName'],\n installed: true,\n version: package['DisplayVersion'],\n type: 'windows',\n }\nend\n".gsub(/^\s*/, '') |