win 0.3.11 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +20 -0
- data/VERSION +1 -1
- data/lib/win/gui/dialog.rb +30 -30
- data/lib/win/gui/input.rb +0 -1
- data/lib/win/gui/message.rb +25 -2
- data/lib/win/library.rb +114 -70
- data/lib/win/system/info.rb +163 -0
- data/lib/win/system/version.rb +571 -0
- data/spec/spec_helper.rb +15 -3
- data/spec/win/error_spec.rb +2 -2
- data/spec/win/gui/message_spec.rb +23 -7
- data/spec/win/library_spec.rb +181 -155
- data/spec/win/system/info_spec.rb +47 -0
- data/spec/win/system/version_spec.rb +169 -0
- metadata +9 -3
@@ -0,0 +1,571 @@
|
|
1
|
+
require 'win/library'
|
2
|
+
|
3
|
+
module Win
|
4
|
+
module System
|
5
|
+
|
6
|
+
# Contains constants, Win32 API functions and convenience methods
|
7
|
+
# related to operating system version.
|
8
|
+
module Version
|
9
|
+
extend Win::Library
|
10
|
+
|
11
|
+
# Processor info constants (obsolete):
|
12
|
+
|
13
|
+
PROCESSOR_INTEL_386 = 386
|
14
|
+
PROCESSOR_INTEL_486 = 486
|
15
|
+
PROCESSOR_INTEL_PENTIUM = 586
|
16
|
+
PROCESSOR_INTEL_IA64 = 2200
|
17
|
+
PROCESSOR_AMD_X8664 = 8664
|
18
|
+
|
19
|
+
VER_SERVER_NT = 0x80000000
|
20
|
+
VER_WORKSTATION_NT = 0x40000000
|
21
|
+
|
22
|
+
# wSuiteMask mask constants:
|
23
|
+
|
24
|
+
# Microsoft Small Business Server was once installed on the system, but may have been upgraded to
|
25
|
+
# another version of Windows. Refer to the Remarks section for more information about this bit flag.
|
26
|
+
VER_SUITE_SMALLBUSINESS = 0x00000001
|
27
|
+
# Windows Server 2008 Enterprise, Windows Server 2003, Enterprise Edition, or Windows 2000 Advanced
|
28
|
+
# Server is installed. Refer to the Remarks section for more information about this bit flag.
|
29
|
+
VER_SUITE_ENTERPRISE = 0x00000002
|
30
|
+
# Microsoft BackOffice components are installed.
|
31
|
+
VER_SUITE_BACKOFFICE = 0x00000004
|
32
|
+
VER_SUITE_COMMUNICATIONS = 0x00000008
|
33
|
+
# Terminal Services is installed. This value is always set. If VER_SUITE_TERMINAL is set but
|
34
|
+
# VER_SUITE_SINGLEUSERTS is not set, the system is running in application server mode.
|
35
|
+
VER_SUITE_TERMINAL = 0x00000010
|
36
|
+
# Microsoft Small Business Server is installed with the restrictive client license in force. Refer to
|
37
|
+
# the Remarks section for more information about this bit flag.
|
38
|
+
VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020
|
39
|
+
# Windows XP Embedded is installed.
|
40
|
+
VER_SUITE_EMBEDDEDNT = 0x00000040
|
41
|
+
# Windows Server 2008 Datacenter, Windows Server 2003, Datacenter Edition, or Windows 2000 Datacenter Server is installed.
|
42
|
+
VER_SUITE_DATACENTER = 0x00000080
|
43
|
+
# Remote Desktop is supported, but only one interactive session is supported. This value is set unless
|
44
|
+
# the system is running in application server mode.
|
45
|
+
VER_SUITE_SINGLEUSERTS = 0x00000100
|
46
|
+
# Windows Vista Home Premium, Windows Vista Home Basic, or Windows XP Home Edition is installed.
|
47
|
+
VER_SUITE_PERSONAL = 0x00000200
|
48
|
+
# Windows Server 2003, Web Edition is installed.
|
49
|
+
VER_SUITE_BLADE = 0x00000400
|
50
|
+
VER_SUITE_EMBEDDED_RESTRICTED = 0x00000800
|
51
|
+
VER_SUITE_SECURITY_APPLIANCE = 0x00001000
|
52
|
+
# Windows Storage Server 2003 R2 or Windows Storage Server 2003is installed.
|
53
|
+
VER_SUITE_STORAGE_SERVER = 0x00002000
|
54
|
+
# Windows Server 2003, Compute Cluster Edition is installed.
|
55
|
+
VER_SUITE_COMPUTE_SERVER = 0x00004000
|
56
|
+
# Windows Home Server is installed.
|
57
|
+
VER_SUITE_WH_SERVER = 0x00008000
|
58
|
+
|
59
|
+
# wProductType mask constants:
|
60
|
+
|
61
|
+
# The operating system is Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows 2000 Pro
|
62
|
+
VER_NT_WORKSTATION = 0x0000001
|
63
|
+
# The system is a domain controller and the operating system is Windows Server 2008, Windows Server
|
64
|
+
# 2003, or Windows 2000 Server.
|
65
|
+
VER_NT_DOMAIN_CONTROLLER = 0x0000002
|
66
|
+
# The operating system is Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
|
67
|
+
# Note that a server that is also a domain controller is reported as VER_NT_DOMAIN_CONTROLLER, not VER_NT_SERVER.
|
68
|
+
VER_NT_SERVER = 0x0000003
|
69
|
+
|
70
|
+
# Platform definitions:
|
71
|
+
|
72
|
+
VER_PLATFORM_WIN32s = 0
|
73
|
+
VER_PLATFORM_WIN32_WINDOWS = 1
|
74
|
+
VER_PLATFORM_WIN32_NT = 2
|
75
|
+
|
76
|
+
# *Version* info type masks (used by VerSetConditionMask and VerifyVersionInfo):
|
77
|
+
VER_MINORVERSION = 0x0000001
|
78
|
+
VER_MAJORVERSION = 0x0000002
|
79
|
+
VER_BUILDNUMBER = 0x0000004
|
80
|
+
VER_PLATFORMID = 0x0000008
|
81
|
+
VER_SERVICEPACKMINOR = 0x0000010
|
82
|
+
VER_SERVICEPACKMAJOR = 0x0000020
|
83
|
+
VER_SUITENAME = 0x0000040
|
84
|
+
VER_PRODUCT_TYPE = 0x0000080
|
85
|
+
|
86
|
+
# *Condition* masks masks (used by VerSetConditionMask):
|
87
|
+
# The current value must be equal to the specified value.
|
88
|
+
VER_EQUAL = 1
|
89
|
+
# The current value must be greater than the specified value.
|
90
|
+
VER_GREATER = 2
|
91
|
+
# The current value must be greater than or equal to the specified value.
|
92
|
+
VER_GREATER_EQUAL = 3
|
93
|
+
# The current value must be less than the specified value.
|
94
|
+
VER_LESS = 4
|
95
|
+
# The current value must be less than or equal to the specified value.
|
96
|
+
VER_LESS_EQUAL = 5
|
97
|
+
# All product suites specified in the wSuiteMask member must be present in the current system.
|
98
|
+
VER_AND = 6
|
99
|
+
# At least one of the specified product suites must be present in the current system.
|
100
|
+
VER_OR = 7
|
101
|
+
|
102
|
+
class << self
|
103
|
+
# Macros defined in windef.h. TODO: put them into some kind of helper?
|
104
|
+
|
105
|
+
def MAKEWORD(a, b)
|
106
|
+
((a & 0xff) | (b & 0xff)) << 8
|
107
|
+
end
|
108
|
+
|
109
|
+
def MAKELONG(a, b)
|
110
|
+
((a & 0xffff) | (b & 0xffff)) << 16
|
111
|
+
end
|
112
|
+
|
113
|
+
def LOWORD(l)
|
114
|
+
l & 0xffff
|
115
|
+
end
|
116
|
+
|
117
|
+
def HIWORD(l)
|
118
|
+
l >> 16
|
119
|
+
end
|
120
|
+
|
121
|
+
def LOBYTE(w)
|
122
|
+
w & 0xff
|
123
|
+
end
|
124
|
+
|
125
|
+
def HIBYTE(w)
|
126
|
+
w >> 8
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# OSVERSIONINFOEX Structure. Contains operating system version information. The information includes major and
|
131
|
+
# minor version numbers, a build number, a platform identifier, and information about product suites and the
|
132
|
+
# latest Service Pack installed on the system. This structure is used with the GetVersionEx and
|
133
|
+
# VerifyVersionInfo functions.
|
134
|
+
#
|
135
|
+
# [*Typedef*] struct { DWORD dwOSVersionInfoSize; DWORD dwMajorVersion; DWORD dwMinorVersion; DWORD
|
136
|
+
# dwBuildNumber; DWORD dwPlatformId; TCHAR szCSDVersion[128]; WORD wServicePackMajor; WORD
|
137
|
+
# wServicePackMinor; WORD wSuiteMask; BYTE wProductType; BYTE wReserved;
|
138
|
+
# } OSVERSIONINFOEX;
|
139
|
+
#
|
140
|
+
# dwOSVersionInfoSize:: The size of this data structure, in bytes. Set this member to sizeof(OSVERSIONINFOEX).
|
141
|
+
# dwMajorVersion:: Major version number of the operating system. This member can be one of the following:
|
142
|
+
# - 5 The operating system is Windows Server 2003 (also R2), Windows XP, or Windows 2000.
|
143
|
+
# - 6 The operating system is Windows Vista or Windows Server 2008.
|
144
|
+
# dwMinorVersion:: Minor version number of the operating system. This member can be one of the following:
|
145
|
+
# - 0 The operating system is Windows Server 2008, Windows Vista, or Windows 2000.
|
146
|
+
# - 1 The operating system is Windows XP.
|
147
|
+
# - 2 The operating system is Windows Server 2003 (also R2) or Windows XP Professional x64
|
148
|
+
# dwBuildNumber:: The build number of the operating system.
|
149
|
+
# dwPlatformId:: The operating system platform. This member can be VER_PLATFORM_WIN32_NT (2).
|
150
|
+
# szCSDVersion:: A null-terminated string, such as "Service Pack 3", that indicates the latest Service Pack
|
151
|
+
# installed on the system. If no Service Pack has been installed, the string is empty.
|
152
|
+
# wServicePackMajor:: The major version number of the latest Service Pack installed on the system. For example,
|
153
|
+
# for Service Pack 3, major version number is 3. If no Service Pack has been installed,
|
154
|
+
# the value is zero.
|
155
|
+
# wServicePackMinor:: The minor version number of the latest Service Pack installed on the system. For example,
|
156
|
+
# for Service Pack 3, the minor version number is 0.
|
157
|
+
# wSuiteMask:: A bit mask that identifies the product suites available on the system. This member can be a
|
158
|
+
# combination of the following values:
|
159
|
+
# VER_SUITE_BACKOFFICE, VER_SUITE_BLADE, VER_SUITE_COMPUTE_SERVER, VER_SUITE_DATACENTER,
|
160
|
+
# VER_SUITE_ENTERPRISE, VER_SUITE_EMBEDDEDNT, VER_SUITE_PERSONAL, VER_SUITE_SINGLEUSERTS,
|
161
|
+
# VER_SUITE_SMALLBUSINESS, VER_SUITE_SMALLBUSINESS_RESTRICTED, VER_SUITE_STORAGE_SERVER,
|
162
|
+
# VER_SUITE_TERMINAL, VER_SUITE_WH_SERVER
|
163
|
+
# wProductType:: Any additional information about the system. This member can be one of the following values:
|
164
|
+
# VER_NT_DOMAIN_CONTROLLER, VER_NT_SERVER, VER_NT_WORKSTATION
|
165
|
+
# wReserved:: Reserved for future use.
|
166
|
+
# ---
|
167
|
+
# *Remarks*:
|
168
|
+
# Relying on version information is not the best way to test for a feature. Instead, refer to the
|
169
|
+
# documentation for the feature of interest. For more information on common techniques for feature
|
170
|
+
# detection, {see Operating System Version}[http://msdn.microsoft.com/en-us/library/ms724832%28v=VS.85%29.aspx].
|
171
|
+
# If you must require a particular operating system, be sure to use it as a minimum supported version,
|
172
|
+
# rather than design the test for the one operating system. This way, your detection code will continue
|
173
|
+
# to work on future versions of Windows.
|
174
|
+
#
|
175
|
+
# If compatibility mode is in effect, the OSVERSIONINFOEX structure contains information about the
|
176
|
+
# operating system that is selected for {application compatibility}[http://msdn.microsoft.com/en-us/library/bb757005.aspx].
|
177
|
+
#
|
178
|
+
# The GetSystemMetrics function provides the following additional information about the current
|
179
|
+
# Windows Server 2003 R2:: SM_SERVERR2
|
180
|
+
# Windows XP Media Center Edition:: SM_MEDIACENTER
|
181
|
+
# Windows XP Starter Edition:: SM_STARTER
|
182
|
+
# Windows XP Tablet PC Edition:: SM_TABLETPC
|
183
|
+
# The following table summarizes the values returned by supported versions of Windows.
|
184
|
+
# Use this information to distinguish between operating systems with identical version numbers.
|
185
|
+
# Windows 7:: 6.1 OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
|
186
|
+
# Windows Server 2008 R2:: 6.1 OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION
|
187
|
+
# Windows Server 2008:: 6.0 OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION
|
188
|
+
# Windows Vista:: 6.0 OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
|
189
|
+
# Windows Server 2003 R2:: 5.2 GetSystemMetrics(SM_SERVERR2) != 0
|
190
|
+
# Windows Home Server:: 5.2 OSVERSIONINFOEX.wSuiteMask & VER_SUITE_WH_SERVER
|
191
|
+
# Windows Server 2003:: 5.2 GetSystemMetrics(SM_SERVERR2) == 0
|
192
|
+
# Windows XP Professional x64 Ed:: 5.2 (OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION) && (SYSTEM_INFO.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
|
193
|
+
# Windows XP:: 5.1
|
194
|
+
# Windows 2000:: 5.0
|
195
|
+
# To determine whether a Win32-based application is running on WOW64, call the IsWow64Process function.
|
196
|
+
# To determine whether the system is running a 64-bit version of Windows, call the GetNativeSystemInfo.
|
197
|
+
#
|
198
|
+
class OSVERSIONINFOEX < FFI::Struct
|
199
|
+
layout :dw_os_version_info_size, :uint32,
|
200
|
+
:dw_major_version, :uint32,
|
201
|
+
:dw_minor_version, :uint32,
|
202
|
+
:dw_build_number, :uint32,
|
203
|
+
:dw_platform_id, :uint32,
|
204
|
+
:sz_csd_version, [:char, 128],
|
205
|
+
:w_service_pack_major, :uint16,
|
206
|
+
:w_service_pack_minor, :uint16,
|
207
|
+
:w_suite_mask, :uint16,
|
208
|
+
:w_product_type, :uchar,
|
209
|
+
:w_reserved, :uchar,
|
210
|
+
end
|
211
|
+
|
212
|
+
##
|
213
|
+
# GetVersion Function retrieves the version number of the current operating system.
|
214
|
+
# *Note*: This function has been superseded by GetVersionEx. New applications should use GetVersionEx or
|
215
|
+
# VerifyVersionInfo.
|
216
|
+
#
|
217
|
+
# [*Syntax*] DWORD WINAPI GetVersion( void );
|
218
|
+
#
|
219
|
+
# This function has no parameters.
|
220
|
+
#
|
221
|
+
# *Returns*:: If the function succeeds, the return value includes the major and minor version numbers of
|
222
|
+
# the operating system in the low-order word, and information about the operating system
|
223
|
+
# platform in the high-order word.
|
224
|
+
# For all platforms, the low-order word contains the version number of the operating system. The
|
225
|
+
# low-order byte of this word specifies the major version number, in hexadecimal notation. The
|
226
|
+
# high-order byte specifies the minor version (revision) number, in hexadecimal notation. The
|
227
|
+
# high-order bit is zero, the next 7 bits represent the build number, and the low-order byte is 5.
|
228
|
+
# ---
|
229
|
+
# *Remarks*:
|
230
|
+
# The GetVersionEx function was developed because many existing applications err when examining the
|
231
|
+
# packed DWORD value returned by GetVersion, transposing the major and minor version numbers.
|
232
|
+
# GetVersionEx forces applications to explicitly examine each element of version information.
|
233
|
+
# VerifyVersionInfo eliminates further potential for error by comparing the required system version with
|
234
|
+
# the current system version for you.
|
235
|
+
# ---
|
236
|
+
# *Requirements*:
|
237
|
+
# Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
|
238
|
+
# Server Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
|
239
|
+
# Header Declared in Winbase.h; include Windows.h.
|
240
|
+
# Library Use Kernel32.lib.
|
241
|
+
# ---
|
242
|
+
# *See* *Also*:
|
243
|
+
# GetVersionEx
|
244
|
+
# VerifyVersionInfo
|
245
|
+
# {Operating System Version}[http://msdn.microsoft.com/en-us/library/ms724832%28v=VS.85%29.aspx]
|
246
|
+
#
|
247
|
+
# ---
|
248
|
+
# <b>Enhanced (snake_case) API: Returns an Array with 3 version numbers: major, minor and build. </b>
|
249
|
+
#
|
250
|
+
# :call-seq:
|
251
|
+
# major, minor, build = [get_]version()
|
252
|
+
#
|
253
|
+
function :GetVersion, [], :uint32,
|
254
|
+
&->(api) {
|
255
|
+
version = api.call
|
256
|
+
major = LOBYTE(LOWORD(version))
|
257
|
+
minor = HIBYTE(LOWORD(version))
|
258
|
+
build = version < 0x80000000 ? HIWORD(version) : 0
|
259
|
+
[major, minor, build] }
|
260
|
+
|
261
|
+
##
|
262
|
+
# GetVersionEx Function retrieves information about the current operating system.
|
263
|
+
#
|
264
|
+
# [*Syntax*] BOOL WINAPI GetVersionEx( LPOSVERSIONINFO lpVersionInfo );
|
265
|
+
#
|
266
|
+
# lpVersionInfo:: <in, out> An OSVERSIONINFO or OSVERSIONINFOEX structure that receives the operating system
|
267
|
+
# information. Before calling the GetVersionEx function, set the dwOSVersionInfoSize member of
|
268
|
+
# the structure as appropriate to indicate which data structure is being passed to this function.
|
269
|
+
#
|
270
|
+
# *Returns*:: If the function succeeds, the return value is a nonzero value. If the function fails, it is zero.
|
271
|
+
# To get extended error information, call GetLastError. The function fails if you specify an invalid
|
272
|
+
# value for the dwOSVersionInfoSize member of the OSVERSIONINFO or OSVERSIONINFOEX structure.
|
273
|
+
# ---
|
274
|
+
# *Remarks*:
|
275
|
+
# Identifying the current operating system is usually not the best way to determine whether a particular
|
276
|
+
# operating system feature is present. This is because the operating system may have had new features
|
277
|
+
# added in a redistributable DLL. Rather than using GetVersionEx to determine the operating system
|
278
|
+
# platform or version number, test for the presence of the feature itself. For more information, see
|
279
|
+
# {Operating System Version}[http://msdn.microsoft.com/en-us/library/ms724832%28v=VS.85%29.aspx].
|
280
|
+
#
|
281
|
+
# The GetSystemMetrics function provides additional information about the current operating system.
|
282
|
+
# To check for specific operating systems or operating system features, use the IsOS function. The
|
283
|
+
# GetProductInfo function retrieves the product type.
|
284
|
+
#
|
285
|
+
# To retrieve information for the operating system on a remote computer, use the NetWkstaGetInfo
|
286
|
+
# function, the Win32_OperatingSystem WMI class, or the OperatingSystem property of the IADsComputer
|
287
|
+
# interface.
|
288
|
+
#
|
289
|
+
# To compare the current system version to a required version, use the VerifyVersionInfo function
|
290
|
+
# instead of using GetVersionEx to perform the comparison yourself.
|
291
|
+
# If compatibility mode is in effect, the GetVersionEx function reports the operating system as it
|
292
|
+
# identifies itself, which may not be the operating system that is installed. For example, if
|
293
|
+
# compatibility mode is in effect, GetVersionEx reports the operating system that is selected for
|
294
|
+
# application compatibility.
|
295
|
+
#
|
296
|
+
# When using the GetVersionEx function to determine whether your application is running on a particular
|
297
|
+
# version of the operating system, check for version numbers that are greater than or equal to the
|
298
|
+
# desired version numbers. This ensures that the test succeeds for later versions of the operating system.
|
299
|
+
# ---
|
300
|
+
# *Requirements*
|
301
|
+
# Windows 2000 Professional +, or Windows 2000 Server +
|
302
|
+
# Header:: Winbase.h (include Windows.h)
|
303
|
+
# Library:: Kernel32.lib
|
304
|
+
# Unicode and ANSI names:: GetVersionExW (Unicode) and GetVersionExA (ANSI)
|
305
|
+
# ---
|
306
|
+
# *See* *Also*
|
307
|
+
# GetVersion
|
308
|
+
# VerifyVersionInfo
|
309
|
+
# OSVERSIONINFO
|
310
|
+
# OSVERSIONINFOEX
|
311
|
+
# {Operating System Version}[http://msdn.microsoft.com/en-us/library/ms724832%28v=VS.85%29.aspx]
|
312
|
+
#
|
313
|
+
# ---
|
314
|
+
# <b>Enhanced (snake_case) API: Takes OSVERSIONINFOEX struct as optional argument, returns
|
315
|
+
# filled OSVERSIONINFOEX struct. You can address members of the struct like this:
|
316
|
+
# version_info[:dw_major_version]. If function fails, it returns nil. </b>
|
317
|
+
#
|
318
|
+
# :call-seq:
|
319
|
+
# version_info = [get_]version_ex(lp_version_info=OSVERSIONINFOEX.new)
|
320
|
+
#
|
321
|
+
function :GetVersionEx, [:pointer], :int8,
|
322
|
+
&->(api, version_info = OSVERSIONINFOEX.new) {
|
323
|
+
version_info[:dw_os_version_info_size] = version_info.size
|
324
|
+
api.call(version_info.to_ptr) == 0 ? nil : version_info }
|
325
|
+
|
326
|
+
##
|
327
|
+
# VerifyVersionInfo Function. Compares a set of operating system version requirements to the corresponding
|
328
|
+
# values for the currently running version of the system.
|
329
|
+
#
|
330
|
+
# [*Syntax*] BOOL VerifyVersionInfo( LPOSVERSIONINFOEX lpVersionInfo, DWORD dwTypeMask, DWORDLONG
|
331
|
+
# dwlConditionMask );
|
332
|
+
#
|
333
|
+
# lpVersionInfo:: A pointer to an OSVERSIONINFOEX structure containing the operating system version requirements
|
334
|
+
# to compare. The dwTypeMask parameter indicates the members of this structure that contain
|
335
|
+
# information to compare. You must set the dwOSVersionInfoSize member of this structure to
|
336
|
+
# sizeof(OSVERSIONINFOEX). You must also specify valid data for the members indicated by
|
337
|
+
# dwTypeMask. The function ignores structure members for which the corresponding dwTypeMask
|
338
|
+
# bit is not set.
|
339
|
+
# dwTypeMask:: Mask that indicates the members of the OSVERSIONINFOEX structure to be tested. This parameter can
|
340
|
+
# be one or more of the following values: VER_BUILDNUMBER, VER_MAJORVERSION, VER_MINORVERSION,
|
341
|
+
# VER_PLATFORMID, VER_SERVICEPACKMAJOR, VER_SERVICEPACKMINOR, VER_SUITENAME, VER_PRODUCT_TYPE
|
342
|
+
# If you are testing the major version, you must also test the minor version and the service pack
|
343
|
+
# major and minor versions.
|
344
|
+
# dwlConditionMask:: The type of comparison to be used for each lpVersionInfo member being compared. To build
|
345
|
+
# this value, call the VerSetConditionMask function or the VER_SET_CONDITION macro once for
|
346
|
+
# each OSVERSIONINFOEX member being compared.
|
347
|
+
#
|
348
|
+
# *Returns*:: If the currently running operating system satisfies the specified requirements, the return
|
349
|
+
# value is a nonzero value. If the current system does not satisfy the requirements, the return
|
350
|
+
# value is zero and GetLastError returns ERROR_OLD_WIN_VERSION. If the function fails, the return
|
351
|
+
# value is zero and GetLastError returns an error code other than ERROR_OLD_WIN_VERSION.
|
352
|
+
# ---
|
353
|
+
# *Remarks*:
|
354
|
+
# The VerifyVersionInfo function retrieves version information about the currently running operating
|
355
|
+
# system and compares it to the valid members of the lpVersionInfo structure. This enables you to easily
|
356
|
+
# determine the presence of a required set of operating system version conditions. It is preferable to
|
357
|
+
# use VerifyVersionInfo rather than calling the GetVersionEx function to perform your own comparisons.
|
358
|
+
# Typically, VerifyVersionInfo returns a nonzero value only if all specified tests succeed. However,
|
359
|
+
# major, minor, and service pack versions are tested in a hierarchical manner because the operating
|
360
|
+
# system version is a combination of these values. If a condition exists for the major version, it
|
361
|
+
# supersedes the conditions specified for minor version and service pack version. (You cannot test for
|
362
|
+
# major version greater than 5 and minor version less than or equal to 1. If you specify such a test,
|
363
|
+
# the function will change the request to test for a minor version greater than 1 because it is
|
364
|
+
# performing a greater than operation on the major version.)
|
365
|
+
#
|
366
|
+
# The function tests these values in this order: major version, minor version, and service pack version.
|
367
|
+
# The function continues testing values while they are equal, and stops when one of the values does not
|
368
|
+
# meet the specified condition. For example, if you test for a system greater than or equal to version
|
369
|
+
# 5.1 service pack 1, the test succeeds if the current version is 6.0. (The major version is greater
|
370
|
+
# than the specified version, so the testing stops.) In the same way, if you test for a system greater
|
371
|
+
# than or equal to version 5.1 service pack 1, the test succeeds if the current version is 5.2. (The
|
372
|
+
# minor version is greater than the specified versions, so the testing stops.) However, if you test for
|
373
|
+
# a system greater than or equal to version 5.1 service pack 1, the test fails if the current version is
|
374
|
+
# 5.0 service pack 2. (The minor version is not greater than the specified version, so the testing stops.)
|
375
|
+
#
|
376
|
+
# To verify a range of system versions, you must call VerifyVersionInfo twice. For example, to verify
|
377
|
+
# that the system version is greater than 5.0 but less than or equal to 5.1, first call
|
378
|
+
# VerifyVersionInfo to test that the major version is 5 and the minor version is greater than 0, then
|
379
|
+
# call VerifyVersionInfo again to test that the major version is 5 and the minor version is less than or
|
380
|
+
# equal to 1.
|
381
|
+
#
|
382
|
+
# Identifying the current operating system is usually not the best way to determine whether a particular
|
383
|
+
# operating system feature is present. This is because the operating system may have had new features
|
384
|
+
# added in a redistributable DLL. Rather than using GetVersionEx to determine the operating system
|
385
|
+
# platform or version number, test for the presence of the feature itself. For more information,
|
386
|
+
# {see Operating System Version}[http://msdn.microsoft.com/en-us/library/ms724832%28v=VS.85%29.aspx].
|
387
|
+
# To verify whether the current operating system is either the Media Center or Tablet PC version of
|
388
|
+
# Windows, call GetSystemMetrics.
|
389
|
+
# ---
|
390
|
+
# *Requirements*
|
391
|
+
# Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
|
392
|
+
# Server Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
|
393
|
+
# Header Declared in Winbase.h; include Windows.h.
|
394
|
+
# Library Use Kernel32.lib.
|
395
|
+
# Unicode Implemented as VerifyVersionInfoW (Unicode) and VerifyVersionInfoA (ANSI).
|
396
|
+
# ---
|
397
|
+
# *See* *Also*
|
398
|
+
# GetVersionEx
|
399
|
+
# VerSetConditionMask
|
400
|
+
# OSVERSIONINFOEX
|
401
|
+
# VER_SET_CONDITION
|
402
|
+
# {Operating System Version}[http://msdn.microsoft.com/en-us/library/ms724832%28v=VS.85%29.aspx]
|
403
|
+
#
|
404
|
+
# ---
|
405
|
+
# <b>Enhanced (snake_case) API: </b>
|
406
|
+
#
|
407
|
+
# :call-seq:
|
408
|
+
# success = verify_version_info(lp_version_info, dw_type_mask, dwl_condition_mask)
|
409
|
+
#
|
410
|
+
function :VerifyVersionInfo, [:pointer, :uint32, :uint64], :int8, boolean: true
|
411
|
+
|
412
|
+
##
|
413
|
+
# VerSetConditionMask Function
|
414
|
+
# Sets the bits of a 64-bit value to indicate the comparison operator to use for a specified operating
|
415
|
+
# system version attribute. This function is used to build the dwlConditionMask parameter of the
|
416
|
+
# VerifyVersionInfo function.
|
417
|
+
#
|
418
|
+
# [*Syntax*] ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
|
419
|
+
# BYTE dwConditionMask );
|
420
|
+
#
|
421
|
+
# dwlConditionMask:: A value to be passed as the dwlConditionMask parameter of the VerifyVersionInfo function.
|
422
|
+
# The function stores the comparison information in the bits of this variable.
|
423
|
+
# Before the first call to VerSetCondition, initialize this variable to zero. For subsequent
|
424
|
+
# calls, pass in the variable used in the previous call.
|
425
|
+
# dwTypeBitMask:: A mask that indicates the member of the OSVERSIONINFOEX structure whose comparison operator is
|
426
|
+
# being set. This value corresponds to one of the bits specified in the dwTypeMask parameter for
|
427
|
+
# the VerifyVersionInfo function. This parameter can be one of the following values:
|
428
|
+
# VER_BUILDNUMBER:: dwBuildNumber
|
429
|
+
# VER_MAJORVERSION:: dwMajorVersion
|
430
|
+
# VER_MINORVERSION:: dwMinorVersion
|
431
|
+
# VER_PLATFORMID:: dwPlatformId
|
432
|
+
# VER_PRODUCT_TYPE:: wProductType
|
433
|
+
# VER_SERVICEPACKMAJOR:: wServicePackMajor
|
434
|
+
# VER_SERVICEPACKMINOR:: wServicePackMinor
|
435
|
+
# VER_SUITENAME:: wSuiteMask
|
436
|
+
# dwConditionMask:: The operator to be used for the comparison. The VerifyVersionInfo function uses this operator
|
437
|
+
# to compare a specified attribute value to the corresponding value for the currently running
|
438
|
+
# system. For all values of dwTypeBitMask other than VER_SUITENAME, this parameter can be one
|
439
|
+
# of the following:
|
440
|
+
# VER_EQUAL:: The current value must be equal to the specified value.
|
441
|
+
# VER_GREATER:: The current value must be greater than the specified value.
|
442
|
+
# VER_GREATER_EQUAL:: The current value must be greater than or equal to the specified value.
|
443
|
+
# VER_LESS:: The current value must be less than the specified value.
|
444
|
+
# VER_LESS_EQUAL:: The current value must be less than or equal to the specified value.
|
445
|
+
# If dwTypeBitMask is VER_SUITENAME, this parameter can be one of the following values:
|
446
|
+
# VER_AND:: All product suites specified in the wSuiteMask member must be present in the system.
|
447
|
+
# VER_OR:: At least one of the specified product suites must be present in the current system.
|
448
|
+
#
|
449
|
+
# *Returns*:: The function returns the condition mask value.
|
450
|
+
# ---
|
451
|
+
# *Remarks*:
|
452
|
+
# Call this function once for each bit set in the dwTypeMask parameter of the VerifyVersionInfo function.
|
453
|
+
# ---
|
454
|
+
# *Requirements*:
|
455
|
+
# Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
|
456
|
+
# Server Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
|
457
|
+
# Header Declared in Winnt.h; include Windows.h.
|
458
|
+
# Library Use Kernel32.lib.
|
459
|
+
# DLL Requires Kernel32.dll.
|
460
|
+
# ---
|
461
|
+
# *See* *Also*:
|
462
|
+
# {Operating System Version}[http://msdn.microsoft.com/en-us/library/ms724832%28v=VS.85%29.aspx]
|
463
|
+
# OSVERSIONINFOEX
|
464
|
+
# VerifyVersionInfo
|
465
|
+
#
|
466
|
+
# ---
|
467
|
+
# <b>Enhanced (snake_case) API: dwl_condition_mask defaults to 0, you can send in an Array of type/condition
|
468
|
+
# pairs instead of single dw_type_bit_mask/dw_condition_mask pair</b>
|
469
|
+
#
|
470
|
+
# :call-seq:
|
471
|
+
# mask = ver_set_condition_mask(previous_mask=0, type_bit_mask, condition_mask)
|
472
|
+
#
|
473
|
+
function :VerSetConditionMask, [:uint64, :uint32, :uchar], :uint64,
|
474
|
+
&->(api, *args) {
|
475
|
+
case args.last
|
476
|
+
when Array
|
477
|
+
mask = args.size == 2 ? args.shift : 0
|
478
|
+
args.last.flatten.each_slice(2) {|pair| mask = api.call(mask, *pair) }
|
479
|
+
mask
|
480
|
+
else
|
481
|
+
mask = args.size == 3 ? args.shift : 0
|
482
|
+
api.call mask, *args
|
483
|
+
end }
|
484
|
+
|
485
|
+
# Convenience methods:
|
486
|
+
|
487
|
+
# Returns true if the current platform is Windows 2000: major version 6, minor version 0.
|
488
|
+
#
|
489
|
+
def windows_2000?
|
490
|
+
major, minor = get_version()
|
491
|
+
major == 5 && minor == 0
|
492
|
+
end
|
493
|
+
|
494
|
+
# Returns true if the current platform is Windows Vista (any variant)
|
495
|
+
# or Windows Server 2008: major version 6, minor version 0.
|
496
|
+
#
|
497
|
+
def windows_vista?
|
498
|
+
major, minor = get_version()
|
499
|
+
major == 6 && minor == 0
|
500
|
+
end
|
501
|
+
|
502
|
+
# Returns true if the current platform is Windows 7
|
503
|
+
# or Windows Server 2008 R2: major version 6, minor version 1.
|
504
|
+
#
|
505
|
+
def windows_7?
|
506
|
+
major, minor = get_version()
|
507
|
+
major == 6 && minor == 1
|
508
|
+
end
|
509
|
+
|
510
|
+
# Returns true if the current platform is Windows XP or Windows XP Pro:
|
511
|
+
# major version 5, minor version 1 (or 2 in the case of a 64-bit Windows XP Pro).
|
512
|
+
#--
|
513
|
+
# Because of the exception for a 64-bit Windows XP Pro, we have to
|
514
|
+
# do things the hard way. For version 2 we look for any of the suite
|
515
|
+
# masks that might be associated with Windows 2003. If we don't find
|
516
|
+
# any of them, assume it's Windows XP.
|
517
|
+
#
|
518
|
+
def windows_xp?
|
519
|
+
ver_info = get_version_ex()
|
520
|
+
|
521
|
+
major = ver_info[:dw_major_version]
|
522
|
+
minor = ver_info[:dw_minor_version]
|
523
|
+
suite = ver_info[:w_suite_mask]
|
524
|
+
|
525
|
+
# Make sure we detect a 64-bit Windows XP Pro
|
526
|
+
if major == 5
|
527
|
+
if minor == 1
|
528
|
+
true
|
529
|
+
elsif minor == 2
|
530
|
+
if (suite & VER_SUITE_BLADE == 0) &&
|
531
|
+
(suite & VER_SUITE_COMPUTE_SERVER == 0) &&
|
532
|
+
(suite & VER_SUITE_DATACENTER == 0) &&
|
533
|
+
(suite & VER_SUITE_ENTERPRISE == 0) &&
|
534
|
+
(suite & VER_SUITE_STORAGE_SERVER == 0)
|
535
|
+
then
|
536
|
+
true
|
537
|
+
end
|
538
|
+
end
|
539
|
+
end || false
|
540
|
+
end
|
541
|
+
|
542
|
+
# Returns true if the current platform is Windows 2003 (any version).
|
543
|
+
# i.e. major version 5, minor version 2.
|
544
|
+
#--
|
545
|
+
# Because of the exception for a 64-bit Windows XP Pro, we have to
|
546
|
+
# do things the hard way. For version 2 we look for any of the suite
|
547
|
+
# masks that might be associated with Windows 2003. If we find any
|
548
|
+
# of them, assume it's Windows 2003.
|
549
|
+
#
|
550
|
+
def windows_2003?
|
551
|
+
ver_info = get_version_ex()
|
552
|
+
|
553
|
+
major = ver_info[:dw_major_version]
|
554
|
+
minor = ver_info[:dw_minor_version]
|
555
|
+
suite = ver_info[:w_suite_mask]
|
556
|
+
|
557
|
+
# Make sure we exclude a 64-bit Windows XP Pro
|
558
|
+
if major == 5 && minor == 2
|
559
|
+
if (suite & VER_SUITE_BLADE > 0) ||
|
560
|
+
(suite & VER_SUITE_COMPUTE_SERVER > 0) ||
|
561
|
+
(suite & VER_SUITE_DATACENTER > 0) ||
|
562
|
+
(suite & VER_SUITE_ENTERPRISE > 0) ||
|
563
|
+
(suite & VER_SUITE_STORAGE_SERVER > 0)
|
564
|
+
then
|
565
|
+
true
|
566
|
+
end
|
567
|
+
end || false
|
568
|
+
end
|
569
|
+
end
|
570
|
+
end
|
571
|
+
end
|