Skip to content

Instantly share code, notes, and snippets.

@eohtake
Created January 1, 2016 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eohtake/3ed2fcb03173c6e379ff to your computer and use it in GitHub Desktop.
Save eohtake/3ed2fcb03173c6e379ff to your computer and use it in GitHub Desktop.
#!/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 = 'unknown'
# This regex goes just before the 3 numbers given to the Java version/update
regexp = "4EA42A62D9304AC4784BF2681408.*"
begin
if RUBY_PLATFORM.downcase.include?("mswin") or RUBY_PLATFORM.downcase.include?("mingw32")
require 'win32/registry'
# Opens the registry key, and uses the regex to match the root of the key.
Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\\Classes\\Installer\\Products') do |version|
version.each_key do | key |
if /#{regexp}/ =~ key
versionkey = key
# Uses the key found above to open the values accordingly to the version.
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
end
end
end
end
end
end
end
end
setcode do
javaplugin64
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment