module Windows::SystemInfo

Constants

ComputerNameDnsDomain
ComputerNameDnsFullyQualified
ComputerNameDnsHostname
ComputerNameMax
ComputerNameNetBIOS

Enum COMPUTER_NAME_FORMAT

ComputerNamePhysicalDnsDomain
ComputerNamePhysicalDnsFullyQualified
ComputerNamePhysicalDnsHostname
ComputerNamePhysicalNetBIOS
PROCESSOR_AMD_X8664
PROCESSOR_INTEL_386

Obsolete processor info constants

PROCESSOR_INTEL_486
PROCESSOR_INTEL_IA64
PROCESSOR_INTEL_PENTIUM
VER_BUILDNUMBER
VER_MAJORVERSION
VER_MINORVERSION

Version info type constants

VER_NT_DOMAIN_CONTROLLER
VER_NT_SERVER
VER_NT_WORKSTATION

Product mask constants

VER_PLATFORMID
VER_PLATFORM_WIN32_NT
VER_PLATFORM_WIN32_WINDOWS
VER_PLATFORM_WIN32s

Platform definitions

VER_PRODUCT_TYPE
VER_SERVER_NT

Suite mask constants

VER_SERVICEPACKMAJOR
VER_SERVICEPACKMINOR
VER_SUITENAME
VER_SUITE_BACKOFFICE
VER_SUITE_BLADE
VER_SUITE_COMMUNICATIONS
VER_SUITE_COMPUTE_SERVER
VER_SUITE_DATACENTER
VER_SUITE_EMBEDDEDNT
VER_SUITE_EMBEDDED_RESTRICTED
VER_SUITE_ENTERPRISE
VER_SUITE_PERSONAL
VER_SUITE_SECURITY_APPLIANCE
VER_SUITE_SINGLEUSERTS
VER_SUITE_SMALLBUSINESS
VER_SUITE_SMALLBUSINESS_RESTRICTED
VER_SUITE_STORAGE_SERVER
VER_SUITE_TERMINAL
VER_WORKSTATION_NT

Private Instance Methods

HIBYTE(w) click to toggle source
# File lib/windows/system_info.rb, line 115
def HIBYTE(w)
  w >> 8
end
HIWORD(l) click to toggle source
# File lib/windows/system_info.rb, line 107
def HIWORD(l)
  l >> 16
end
LOBYTE(w) click to toggle source
# File lib/windows/system_info.rb, line 111
def LOBYTE(w)
  w & 0xff
end
LOWORD(l) click to toggle source
# File lib/windows/system_info.rb, line 103
def LOWORD(l)
  l & 0xffff
end
MAKELONG(a, b) click to toggle source
# File lib/windows/system_info.rb, line 99
def MAKELONG(a, b)
  ((a & 0xffff) | ((b & 0xffff) << 16))
end
MAKEWORD(a, b) click to toggle source

These macros are from windef.h, but I've put them here for now since they can be used in conjunction with some of the functions declared in this module.

# File lib/windows/system_info.rb, line 95
def MAKEWORD(a, b)
  ((a & 0xff) | ((b & 0xff) << 8))
end
windows_2000?() click to toggle source

Returns true if the current platform is Vista (any variant) or Windows Server 2008, i.e. major version 6, minor version 0.

# File lib/windows/system_info.rb, line 134
def windows_2000?
  version = GetVersion()
  LOBYTE(LOWORD(version)) == 5 && HIBYTE(LOWORD(version)) == 0
end
windows_2003?() click to toggle source

Returns true if the current platform is Windows 2003 (any version). i.e. major version 5, minor version 2.

# File lib/windows/system_info.rb, line 189
def windows_2003?
  bool = false

  buf = 0.chr * 156
  buf[0,4] = [buf.size].pack("L") # Set dwOSVersionInfoSize

  GetVersionEx(buf)

  major = buf[4,4].unpack("L")[0]
  minor = buf[8,4].unpack("L")[0]
  suite = buf[152,2].unpack("S")[0]

  # Make sure we exclude a 64-bit Windows XP Pro
  if major == 5 && minor == 2
    if (suite & VER_SUITE_BLADE > 0)          ||
       (suite & VER_SUITE_COMPUTE_SERVER > 0) ||
       (suite & VER_SUITE_DATACENTER > 0)     ||
       (suite & VER_SUITE_ENTERPRISE > 0)     ||
       (suite & VER_SUITE_STORAGE_SERVER > 0)
    then
      bool = true
    end
  end

  bool
end
windows_7?() click to toggle source
# File lib/windows/system_info.rb, line 224
def windows_7?
  version = GetVersion()
  LOBYTE(LOWORD(version)) == 6 && HIBYTE(LOWORD(version)) == 1
end
windows_version() click to toggle source

Returns a float indicating the major and minor version of Windows, e.g. 5.1, 6.0, etc.

# File lib/windows/system_info.rb, line 122
def windows_version
  version = GetVersion()
  major = LOBYTE(LOWORD(version))
  minor = HIBYTE(LOWORD(version))
  "#{major}.#{minor}".to_f
end
windows_vista?() click to toggle source

Returns true if the current platform is Windows Vista (any variant) or Windows Server 2008, i.e. major version 6, minor version 0.

# File lib/windows/system_info.rb, line 219
def windows_vista?
  version = GetVersion()
  LOBYTE(LOWORD(version)) == 6 && HIBYTE(LOWORD(version)) == 0
end
windows_xp?() click to toggle source

Returns true if the current platform is Windows XP or Windows XP Pro, i.e. major version 5, minor version 1 (or 2 in the case of a 64-bit Windows XP Pro).

# File lib/windows/system_info.rb, line 148
def windows_xp?
  bool = false

  buf = 0.chr * 156
  buf[0,4] = [buf.size].pack("L") # Set dwOSVersionInfoSize

  GetVersionEx(buf)

  major = buf[4,4].unpack("L")[0]
  minor = buf[8,4].unpack("L")[0]
  suite = buf[152,2].unpack("S")[0]

  # Make sure we detect a 64-bit Windows XP Pro
  if major == 5
    if minor == 1
      bool = true
    elsif minor == 2
      if (suite & VER_SUITE_BLADE == 0)          &&
         (suite & VER_SUITE_COMPUTE_SERVER == 0) &&
         (suite & VER_SUITE_DATACENTER == 0)     &&
         (suite & VER_SUITE_ENTERPRISE == 0)     &&
         (suite & VER_SUITE_STORAGE_SERVER == 0)
      then
        bool = true
      end
    else
      # Do nothing - already false
    end
  end

  bool
end