Module: Windows::SystemInfo

Defined in:
lib/windows/system_info.rb

Constant Summary collapse

PROCESSOR_INTEL_386 =

Obsolete processor info constants

386
PROCESSOR_INTEL_486 =
486
PROCESSOR_INTEL_PENTIUM =
586
PROCESSOR_INTEL_IA64 =
2200
PROCESSOR_AMD_X8664 =
8664
VER_SERVER_NT =

Suite mask constants

0x80000000
VER_WORKSTATION_NT =
0x40000000
VER_SUITE_SMALLBUSINESS =
0x00000001
VER_SUITE_ENTERPRISE =
0x00000002
VER_SUITE_BACKOFFICE =
0x00000004
VER_SUITE_COMMUNICATIONS =
0x00000008
VER_SUITE_TERMINAL =
0x00000010
VER_SUITE_SMALLBUSINESS_RESTRICTED =
0x00000020
VER_SUITE_EMBEDDEDNT =
0x00000040
VER_SUITE_DATACENTER =
0x00000080
VER_SUITE_SINGLEUSERTS =
0x00000100
VER_SUITE_PERSONAL =
0x00000200
VER_SUITE_BLADE =
0x00000400
VER_SUITE_EMBEDDED_RESTRICTED =
0x00000800
VER_SUITE_SECURITY_APPLIANCE =
0x00001000
VER_SUITE_STORAGE_SERVER =
0x00002000
VER_SUITE_COMPUTE_SERVER =
0x00004000
VER_NT_WORKSTATION =

Product mask constants

0x0000001
VER_NT_DOMAIN_CONTROLLER =
0x0000002
VER_NT_SERVER =
0x0000003
VER_PLATFORM_WIN32s =

Platform definitions

0
VER_PLATFORM_WIN32_WINDOWS =
1
VER_PLATFORM_WIN32_NT =
2
VER_MINORVERSION =

Version info type constants

0x0000001
VER_MAJORVERSION =
0x0000002
VER_BUILDNUMBER =
0x0000004
VER_PLATFORMID =
0x0000008
VER_SERVICEPACKMINOR =
0x0000010
VER_SERVICEPACKMAJOR =
0x0000020
VER_SUITENAME =
0x0000040
VER_PRODUCT_TYPE =
0x0000080
ComputerNameNetBIOS =

Enum COMPUTER_NAME_FORMAT

0
ComputerNameDnsHostname =
1
ComputerNameDnsDomain =
2
ComputerNameDnsFullyQualified =
3
ComputerNamePhysicalNetBIOS =
4
ComputerNamePhysicalDnsHostname =
5
ComputerNamePhysicalDnsDomain =
6
ComputerNamePhysicalDnsFullyQualified =
7
ComputerNameMax =
8

Instance Method Summary collapse

Instance Method Details

#HIBYTE(w) ⇒ Object



113
114
115
# File 'lib/windows/system_info.rb', line 113

def HIBYTE(w)
   w >> 8
end

#HIWORD(l) ⇒ Object



105
106
107
# File 'lib/windows/system_info.rb', line 105

def HIWORD(l)
   l >> 16
end

#LOBYTE(w) ⇒ Object



109
110
111
# File 'lib/windows/system_info.rb', line 109

def LOBYTE(w)
   w & 0xff
end

#LOWORD(l) ⇒ Object



101
102
103
# File 'lib/windows/system_info.rb', line 101

def LOWORD(l)
   l & 0xffff
end

#MAKELONG(a, b) ⇒ Object



97
98
99
# File 'lib/windows/system_info.rb', line 97

def MAKELONG(a, b)
   ((a & 0xffff) | (b & 0xffff)) << 16
end

#MAKEWORD(a, b) ⇒ Object

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.



93
94
95
# File 'lib/windows/system_info.rb', line 93

def MAKEWORD(a, b)
   ((a & 0xff) | (b & 0xff)) << 8
end

#windows_2000?Boolean

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

Returns:

  • (Boolean)


132
133
134
135
# File 'lib/windows/system_info.rb', line 132

def windows_2000?
   version = GetVersion()
   LOBYTE(LOWORD(version)) == 5 && HIBYTE(LOWORD(version)) == 0
end

#windows_2003?Boolean

Returns true if the current platform is Windows 2003 (any version). i.e. major version 5, minor version 2. – Because of the exception for a 64-bit Windows XP Pro, we have to do things the hard way. For version 2 we look for any of the suite masks that might be associated with Windows 2003. If we find any of them, assume it’s Windows 2003.

Returns:

  • (Boolean)


187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/windows/system_info.rb', line 187

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_versionObject

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



120
121
122
123
124
125
# File 'lib/windows/system_info.rb', line 120

def windows_version
   version = GetVersion()
   major = LOBYTE(LOWORD(version))
   minor = HIBYTE(LOWORD(version))
   eval("Float(#{major}.#{minor})")
end

#windows_vista?Boolean

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

Returns:

  • (Boolean)


217
218
219
220
# File 'lib/windows/system_info.rb', line 217

def windows_vista?
   version = GetVersion()
   LOBYTE(LOWORD(version)) == 6 && HIBYTE(LOWORD(version)) == 0
end

#windows_xp?Boolean

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). – Because of the exception for a 64-bit Windows XP Pro, we have to do things the hard way. For version 2 we look for any of the suite masks that might be associated with Windows 2003. If we don’t find any of them, assume it’s Windows XP.

Returns:

  • (Boolean)


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/windows/system_info.rb', line 146

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