class Chef::ReservedNames::Win32::Version

Constants

WIN_VERSIONS

Attributes

build_number[R]
major_version[R]
minor_version[R]

Public Class Methods

new() click to toggle source
# File lib/chef/win32/version.rb, line 70
def initialize
  @major_version, @minor_version, @build_number = get_version
  ver_info = get_version_ex
  @product_type = ver_info[:w_product_type]
  @suite_mask = ver_info[:w_suite_mask]
  @sp_major_version = ver_info[:w_service_pack_major]
  @sp_minor_version = ver_info[:w_service_pack_minor]

  # Obtain sku information for the purpose of identifying
  # datacenter, cluster, and core skus
  @sku = get_product_info(@major_version, @minor_version, @sp_major_version, @sp_minor_version)
end

Private Class Methods

get_system_metrics(n_index) click to toggle source

Ruby implementation of msdn.microsoft.com/en-us/library/ms724833(v=vs.85).aspx msdn.microsoft.com/en-us/library/ms724358(v=vs.85).aspx

# File lib/chef/win32/version.rb, line 39
def self.get_system_metrics(n_index)
  GetSystemMetrics(n_index)
end
method_name_from_marketing_name(marketing_name) click to toggle source
# File lib/chef/win32/version.rb, line 45
def self.method_name_from_marketing_name(marketing_name)
  "#{marketing_name.gsub(/\s/, '_').tr('.', '_').downcase}?"
  # "#{marketing_name.gsub(/\s/, '_').gsub(//, '_').downcase}?"
end

Public Instance Methods

win_10_creators_or_higher?() click to toggle source
# File lib/chef/win32/version.rb, line 112
def win_10_creators_or_higher?
  windows_10? && build_number >= 15063
end

Private Instance Methods

get_product_info(major, minor, sp_major, sp_minor) click to toggle source
# File lib/chef/win32/version.rb, line 143
def get_product_info(major, minor, sp_major, sp_minor)
  out = FFI::MemoryPointer.new(:uint32)
  GetProductInfo(major, minor, sp_major, sp_minor, out)
  out.get_uint(0)
end
get_version() click to toggle source
# File lib/chef/win32/version.rb, line 118
def get_version
  # Use WMI here because API's like GetVersion return faked
  # version numbers on Windows Server 2012 R2 and Windows 8.1 --
  # WMI always returns the truth. See article at
  # http://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx

  wmi = WmiLite::Wmi.new
  os_info = wmi.first_of("Win32_OperatingSystem")
  os_version = os_info["version"]

  # The operating system version is a string in the following form
  # that can be split into components based on the '.' delimiter:
  # MajorVersionNumber.MinorVersionNumber.BuildNumber
  os_version.split(".").collect { |version_string| version_string.to_i }
end
get_version_ex() click to toggle source
# File lib/chef/win32/version.rb, line 134
def get_version_ex
  lp_version_info = OSVERSIONINFOEX.new
  lp_version_info[:dw_os_version_info_size] = OSVERSIONINFOEX.size
  unless GetVersionExW(lp_version_info)
    Chef::ReservedNames::Win32::Error.raise!
  end
  lp_version_info
end