-
-
Save greglarkin/83fa5d54215fcbf93983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# | |
# | |
# author: Eric Ohtake | |
# | |
# The custom fact fetches the Java Plugin 64 bits version currently installed on the system. | |
# | |
## Key for the version v8u65 HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\4EA42A62D9304AC4784BF2681408560F | |
## Key for the version v8u66 HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\4EA42A62D9304AC4784BF2681408660F | |
Facter.add('javaplugin64') do | |
confine :kernel => :windows | |
javaplugin64 = '' | |
# This regex goes just before the 3 numbers given to the Java version/update | |
regexp = '4EA42A62D9304AC4784BF268140.*' | |
begin | |
if RUBY_PLATFORM.downcase.include?('mswin') or RUBY_PLATFORM.downcase.include?('mingw32') | |
require 'win32/registry' | |
versionkeys = Array.new | |
# Opens the registry key, and uses the regex to match the root of the key. Then add all the matches to the array. | |
Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\\Classes\\Installer\\Products') do | version | | |
version.each_key do | key | | |
if /#{regexp}/ =~ key | |
versionkeys << key | |
end | |
end | |
end | |
# Uses the key found above to open the values accordingly to the version. | |
versionkeys.each do | versionkey | | |
Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\\Classes\\Installer\\Products\\#{versionkey}") do |reg| | |
reg.each do | name,type,data | | |
if name.eql?('ProductName') | |
javaplugin64 << data.concat('; ') | |
end | |
end | |
end | |
end | |
end | |
end | |
setcode do | |
javaplugin64.chomp('; ') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment