windows-pr 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,86 +1,86 @@
1
- require 'windows/api'
2
-
3
- module Windows
4
- module Socket
5
- API.auto_namespace = 'Windows::Socket'
6
- API.auto_constant = true
7
- API.auto_method = true
8
- API.auto_unicode = true
9
-
10
- private
11
-
12
- # Constants
13
-
14
- IPPROTO_IP = 0 # dummy for IP
15
- IPPROTO_ICMP = 1 # control message protocol
16
- IPPROTO_IGMP = 2 # group management protocol
17
- IPPROTO_GGP = 3 # gateway^2 (deprecated)
18
- IPPROTO_TCP = 6 # tcp
19
- IPPROTO_PUP = 12 # pup
20
- IPPROTO_UDP = 17 # user datagram protocol
21
- IPPROTO_IDP = 22 # xns idp
22
- IPPROTO_ND = 77 # UNOFFICIAL net disk proto
23
- IPPROTO_RAW = 255 # raw IP packet
24
- IPPROTO_MAX = 256
25
-
26
- NSPROTO_IPX = 1000
27
- NSPROTO_SPX = 1256
28
- NSPROTO_SPXII = 1257
29
-
30
- # Functions
31
-
32
- API.new('accept', 'LPP', 'L', 'ws2_32')
33
- API.new('AcceptEx', 'LLPLLLPP', 'B', 'mswsock')
34
- API.new('bind', 'LPI', 'I', 'ws2_32')
35
- API.new('closesocket', 'L', 'I', 'ws2_32')
36
- API.new('connect', 'LPI', 'I', 'ws2_32')
37
- API.new('EnumProtocols', 'PPP', 'I', 'mswsock')
38
- API.new('GetAcceptExSockaddrs', 'PLLLPPPP', 'V', 'mswsock')
39
- API.new('GetAddressByName', 'LPPPLPPPPP', 'I', 'mswsock')
40
- API.new('gethostbyaddr', 'SII', 'P', 'ws2_32')
41
- API.new('gethostbyname', 'S', 'P', 'ws2_32')
42
- API.new('gethostname', 'PI', 'I', 'ws2_32')
43
- API.new('GetNameByType', 'PPL', 'I', 'mswsock')
44
- API.new('getpeername', 'LPP', 'I', 'ws2_32')
45
- API.new('getprotobyname', 'S', 'P', 'ws2_32')
46
- API.new('getprotobynumber', 'I', 'P', 'ws2_32')
47
- API.new('getservbyport', 'IS', 'P', 'ws2_32')
48
- API.new('GetService', 'LPSLPPP', 'I', 'mswsock')
49
- API.new('getsockname', 'LPP', 'I', 'ws2_32')
50
- API.new('getsockopt', 'LIIPP', 'I', 'ws2_32')
51
- API.new('GetTypeByName', 'LIIPP', 'I', 'mswsock')
52
- API.new('htonl', 'L', 'L', 'ws2_32')
53
- API.new('htons', 'S', 'S', 'ws2_32')
54
- API.new('inet_addr', 'S', 'L', 'ws2_32')
55
- API.new('inet_ntoa', 'P', 'S', 'ws2_32')
56
- API.new('ioctlsocket', 'LLP', 'I', 'ws2_32')
57
- API.new('listen', 'LI', 'I', 'ws2_32')
58
- API.new('ntohl', 'L', 'L', 'ws2_32')
59
- API.new('ntohs', 'S', 'S', 'ws2_32')
60
- API.new('recv', 'LPII', 'I', 'ws2_32')
61
- API.new('recvfrom', 'LPIIPP', 'I', 'ws2_32')
62
- API.new('send', 'LSII', 'I', 'ws2_32')
63
- API.new('sendto', 'LSIIPI', 'I', 'ws2_32')
64
- API.new('SetService', 'LLLPPP', 'I', 'mswsock')
65
- API.new('setsockopt', 'LIISI', 'I', 'ws2_32')
66
- API.new('shutdown', 'LI', 'I', 'ws2_32')
67
- API.new('socket', 'III', 'L', 'ws2_32')
68
- API.new('TransmitFile', 'LLLLPPL', 'B', 'mswsock')
69
-
70
- begin
71
- API.new('freeaddrinfo', 'P', 'V', 'ws2_32')
72
- API.new('FreeAddrInfoEx', 'P', 'V', 'ws2_32')
73
- API.new('FreeAddrInfoW', 'P', 'V', 'ws2_32')
74
- API.new('getaddrinfo', 'PPPP', 'I', 'ws2_32')
75
- API.new('GetAddrInfoEx', 'PPLPPPPPPP', 'I', 'ws2_32')
76
- API.new('GetAddrInfoW', 'PPPP', 'I', 'ws2_32')
77
- API.new('getnameinfo', 'PLPLPLI', 'I', 'ws2_32')
78
- API.new('GetNameInfoW', 'PLPLPLI', 'I', 'ws2_32')
79
- API.new('InetNtop', 'IPPL', 'P', 'ws2_32')
80
- API.new('inet_pton', 'IPP', 'I', 'ws2_32')
81
- API.new('SetAddrInfoEx', 'SSPLPLLPPPPP', 'I', 'ws2_32')
82
- rescue Win32::API::LoadLibraryError
83
- # XP or later
84
- end
85
- end
86
- end
1
+ require 'windows/api'
2
+
3
+ module Windows
4
+ module Socket
5
+ API.auto_namespace = 'Windows::Socket'
6
+ API.auto_constant = true
7
+ API.auto_method = true
8
+ API.auto_unicode = true
9
+
10
+ private
11
+
12
+ # Constants
13
+
14
+ IPPROTO_IP = 0 # dummy for IP
15
+ IPPROTO_ICMP = 1 # control message protocol
16
+ IPPROTO_IGMP = 2 # group management protocol
17
+ IPPROTO_GGP = 3 # gateway^2 (deprecated)
18
+ IPPROTO_TCP = 6 # tcp
19
+ IPPROTO_PUP = 12 # pup
20
+ IPPROTO_UDP = 17 # user datagram protocol
21
+ IPPROTO_IDP = 22 # xns idp
22
+ IPPROTO_ND = 77 # UNOFFICIAL net disk proto
23
+ IPPROTO_RAW = 255 # raw IP packet
24
+ IPPROTO_MAX = 256
25
+
26
+ NSPROTO_IPX = 1000
27
+ NSPROTO_SPX = 1256
28
+ NSPROTO_SPXII = 1257
29
+
30
+ # Functions
31
+
32
+ API.new('accept', 'LPP', 'L', 'ws2_32')
33
+ API.new('AcceptEx', 'LLPLLLPP', 'B', 'mswsock')
34
+ API.new('bind', 'LPI', 'I', 'ws2_32')
35
+ API.new('closesocket', 'L', 'I', 'ws2_32')
36
+ API.new('connect', 'LPI', 'I', 'ws2_32')
37
+ API.new('EnumProtocols', 'PPP', 'I', 'mswsock')
38
+ API.new('GetAcceptExSockaddrs', 'PLLLPPPP', 'V', 'mswsock')
39
+ API.new('GetAddressByName', 'LPPPLPPPPP', 'I', 'mswsock')
40
+ API.new('gethostbyaddr', 'SII', 'P', 'ws2_32')
41
+ API.new('gethostbyname', 'S', 'P', 'ws2_32')
42
+ API.new('gethostname', 'PI', 'I', 'ws2_32')
43
+ API.new('GetNameByType', 'PPL', 'I', 'mswsock')
44
+ API.new('getpeername', 'LPP', 'I', 'ws2_32')
45
+ API.new('getprotobyname', 'S', 'P', 'ws2_32')
46
+ API.new('getprotobynumber', 'I', 'P', 'ws2_32')
47
+ API.new('getservbyport', 'IS', 'P', 'ws2_32')
48
+ API.new('GetService', 'LPSLPPP', 'I', 'mswsock')
49
+ API.new('getsockname', 'LPP', 'I', 'ws2_32')
50
+ API.new('getsockopt', 'LIIPP', 'I', 'ws2_32')
51
+ API.new('GetTypeByName', 'LIIPP', 'I', 'mswsock')
52
+ API.new('htonl', 'L', 'L', 'ws2_32')
53
+ API.new('htons', 'S', 'S', 'ws2_32')
54
+ API.new('inet_addr', 'S', 'L', 'ws2_32')
55
+ API.new('inet_ntoa', 'P', 'S', 'ws2_32')
56
+ API.new('ioctlsocket', 'LLP', 'I', 'ws2_32')
57
+ API.new('listen', 'LI', 'I', 'ws2_32')
58
+ API.new('ntohl', 'L', 'L', 'ws2_32')
59
+ API.new('ntohs', 'S', 'S', 'ws2_32')
60
+ API.new('recv', 'LPII', 'I', 'ws2_32')
61
+ API.new('recvfrom', 'LPIIPP', 'I', 'ws2_32')
62
+ API.new('send', 'LSII', 'I', 'ws2_32')
63
+ API.new('sendto', 'LSIIPI', 'I', 'ws2_32')
64
+ API.new('SetService', 'LLLPPP', 'I', 'mswsock')
65
+ API.new('setsockopt', 'LIISI', 'I', 'ws2_32')
66
+ API.new('shutdown', 'LI', 'I', 'ws2_32')
67
+ API.new('socket', 'III', 'L', 'ws2_32')
68
+ API.new('TransmitFile', 'LLLLPPL', 'B', 'mswsock')
69
+
70
+ begin
71
+ API.new('freeaddrinfo', 'P', 'V', 'ws2_32')
72
+ API.new('FreeAddrInfoEx', 'P', 'V', 'ws2_32')
73
+ API.new('FreeAddrInfoW', 'P', 'V', 'ws2_32')
74
+ API.new('getaddrinfo', 'PPPP', 'I', 'ws2_32')
75
+ API.new('GetAddrInfoEx', 'PPLPPPPPPP', 'I', 'ws2_32')
76
+ API.new('GetAddrInfoW', 'PPPP', 'I', 'ws2_32')
77
+ API.new('getnameinfo', 'PLPLPLI', 'I', 'ws2_32')
78
+ API.new('GetNameInfoW', 'PLPLPLI', 'I', 'ws2_32')
79
+ API.new('InetNtop', 'IPPL', 'P', 'ws2_32')
80
+ API.new('inet_pton', 'IPP', 'I', 'ws2_32')
81
+ API.new('SetAddrInfoEx', 'SSPLPLLPPPPP', 'I', 'ws2_32')
82
+ rescue Win32::API::LoadLibraryError
83
+ # XP or later
84
+ end
85
+ end
86
+ end
@@ -1,229 +1,229 @@
1
- require 'windows/api'
2
-
3
- module Windows
4
- module SystemInfo
5
- API.auto_namespace = 'Windows::SystemInfo'
6
- API.auto_constant = true
7
- API.auto_method = true
8
- API.auto_unicode = true
9
-
10
- private
11
-
12
- # Obsolete processor info constants
13
-
14
- PROCESSOR_INTEL_386 = 386
15
- PROCESSOR_INTEL_486 = 486
16
- PROCESSOR_INTEL_PENTIUM = 586
17
- PROCESSOR_INTEL_IA64 = 2200
18
- PROCESSOR_AMD_X8664 = 8664
19
-
20
- # Suite mask constants
21
-
22
- VER_SERVER_NT = 0x80000000
23
- VER_WORKSTATION_NT = 0x40000000
24
- VER_SUITE_SMALLBUSINESS = 0x00000001
25
- VER_SUITE_ENTERPRISE = 0x00000002
26
- VER_SUITE_BACKOFFICE = 0x00000004
27
- VER_SUITE_COMMUNICATIONS = 0x00000008
28
- VER_SUITE_TERMINAL = 0x00000010
29
- VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020
30
- VER_SUITE_EMBEDDEDNT = 0x00000040
31
- VER_SUITE_DATACENTER = 0x00000080
32
- VER_SUITE_SINGLEUSERTS = 0x00000100
33
- VER_SUITE_PERSONAL = 0x00000200
34
- VER_SUITE_BLADE = 0x00000400
35
- VER_SUITE_EMBEDDED_RESTRICTED = 0x00000800
36
- VER_SUITE_SECURITY_APPLIANCE = 0x00001000
37
- VER_SUITE_STORAGE_SERVER = 0x00002000
38
- VER_SUITE_COMPUTE_SERVER = 0x00004000
39
-
40
- # Product mask constants
41
-
42
- VER_NT_WORKSTATION = 0x0000001
43
- VER_NT_DOMAIN_CONTROLLER = 0x0000002
44
- VER_NT_SERVER = 0x0000003
45
-
46
- # Platform definitions
47
-
48
- VER_PLATFORM_WIN32s = 0
49
- VER_PLATFORM_WIN32_WINDOWS = 1
50
- VER_PLATFORM_WIN32_NT = 2
51
-
52
- # Version info type constants
53
-
54
- VER_MINORVERSION = 0x0000001
55
- VER_MAJORVERSION = 0x0000002
56
- VER_BUILDNUMBER = 0x0000004
57
- VER_PLATFORMID = 0x0000008
58
- VER_SERVICEPACKMINOR = 0x0000010
59
- VER_SERVICEPACKMAJOR = 0x0000020
60
- VER_SUITENAME = 0x0000040
61
- VER_PRODUCT_TYPE = 0x0000080
62
-
63
- # Enum COMPUTER_NAME_FORMAT
64
-
65
- ComputerNameNetBIOS = 0
66
- ComputerNameDnsHostname = 1
67
- ComputerNameDnsDomain = 2
68
- ComputerNameDnsFullyQualified = 3
69
- ComputerNamePhysicalNetBIOS = 4
70
- ComputerNamePhysicalDnsHostname = 5
71
- ComputerNamePhysicalDnsDomain = 6
72
- ComputerNamePhysicalDnsFullyQualified = 7
73
- ComputerNameMax = 8
74
-
75
- API.new('ExpandEnvironmentStrings', 'PPL', 'L')
76
- API.new('GetComputerName', 'PP', 'B')
77
- API.new('GetComputerNameEx', 'PPP', 'B')
78
- API.new('GetSystemInfo', 'P', 'V')
79
- API.new('GetUserName', 'PP', 'B', 'advapi32')
80
- API.new('GetUserNameEx', 'LPP', 'B', 'secur32')
81
- API.new('GetVersion', 'V', 'L')
82
- API.new('GetVersionEx', 'P', 'B')
83
- API.new('GetWindowsDirectory', 'PI', 'I')
84
-
85
- begin
86
- API.new('GetSystemWow64Directory', 'PI', 'I')
87
- rescue Win32::API::LoadLibraryError
88
- # XP or later
89
- end
90
-
91
- # These macros are from windef.h, but I've put them here for now
92
- # since they can be used in conjunction with some of the functions
93
- # declared in this module.
94
-
95
- def MAKEWORD(a, b)
96
- ((a & 0xff) | ((b & 0xff) << 8))
97
- end
98
-
99
- def MAKELONG(a, b)
100
- ((a & 0xffff) | ((b & 0xffff) << 16))
101
- end
102
-
103
- def LOWORD(l)
104
- l & 0xffff
105
- end
106
-
107
- def HIWORD(l)
108
- l >> 16
109
- end
110
-
111
- def LOBYTE(w)
112
- w & 0xff
113
- end
114
-
115
- def HIBYTE(w)
116
- w >> 8
117
- end
118
-
119
- # Returns a float indicating the major and minor version of Windows,
120
- # e.g. 5.1, 6.0, etc.
121
- #
122
- def windows_version
123
- version = GetVersion()
124
- major = LOBYTE(LOWORD(version))
125
- minor = HIBYTE(LOWORD(version))
126
- eval("Float(#{major}.#{minor})")
127
- end
128
-
129
- # Custom methods that may come in handy
130
-
131
- # Returns true if the current platform is Vista (any variant) or Windows
132
- # Server 2008, i.e. major version 6, minor version 0.
133
- #
134
- def windows_2000?
135
- version = GetVersion()
136
- LOBYTE(LOWORD(version)) == 5 && HIBYTE(LOWORD(version)) == 0
137
- end
138
-
139
- # Returns true if the current platform is Windows XP or Windows XP
140
- # Pro, i.e. major version 5, minor version 1 (or 2 in the case of a
141
- # 64-bit Windows XP Pro).
142
- #--
143
- # Because of the exception for a 64-bit Windows XP Pro, we have to
144
- # do things the hard way. For version 2 we look for any of the suite
145
- # masks that might be associated with Windows 2003. If we don't find
146
- # any of them, assume it's Windows XP.
147
- #
148
- def windows_xp?
149
- bool = false
150
-
151
- buf = 0.chr * 156
152
- buf[0,4] = [buf.size].pack("L") # Set dwOSVersionInfoSize
153
-
154
- GetVersionEx(buf)
155
-
156
- major = buf[4,4].unpack("L")[0]
157
- minor = buf[8,4].unpack("L")[0]
158
- suite = buf[152,2].unpack("S")[0]
159
-
160
- # Make sure we detect a 64-bit Windows XP Pro
161
- if major == 5
162
- if minor == 1
163
- bool = true
164
- elsif minor == 2
165
- if (suite & VER_SUITE_BLADE == 0) &&
166
- (suite & VER_SUITE_COMPUTE_SERVER == 0) &&
167
- (suite & VER_SUITE_DATACENTER == 0) &&
168
- (suite & VER_SUITE_ENTERPRISE == 0) &&
169
- (suite & VER_SUITE_STORAGE_SERVER == 0)
170
- then
171
- bool = true
172
- end
173
- else
174
- # Do nothing - already false
175
- end
176
- end
177
-
178
- bool
179
- end
180
-
181
- # Returns true if the current platform is Windows 2003 (any version).
182
- # i.e. major version 5, minor version 2.
183
- #--
184
- # Because of the exception for a 64-bit Windows XP Pro, we have to
185
- # do things the hard way. For version 2 we look for any of the suite
186
- # masks that might be associated with Windows 2003. If we find any
187
- # of them, assume it's Windows 2003.
188
- #
189
- def windows_2003?
190
- bool = false
191
-
192
- buf = 0.chr * 156
193
- buf[0,4] = [buf.size].pack("L") # Set dwOSVersionInfoSize
194
-
195
- GetVersionEx(buf)
196
-
197
- major = buf[4,4].unpack("L")[0]
198
- minor = buf[8,4].unpack("L")[0]
199
- suite = buf[152,2].unpack("S")[0]
200
-
201
- # Make sure we exclude a 64-bit Windows XP Pro
202
- if major == 5 && minor == 2
203
- if (suite & VER_SUITE_BLADE > 0) ||
204
- (suite & VER_SUITE_COMPUTE_SERVER > 0) ||
205
- (suite & VER_SUITE_DATACENTER > 0) ||
206
- (suite & VER_SUITE_ENTERPRISE > 0) ||
207
- (suite & VER_SUITE_STORAGE_SERVER > 0)
208
- then
209
- bool = true
210
- end
211
- end
212
-
213
- bool
214
- end
215
-
216
- # Returns true if the current platform is Windows Vista (any variant)
217
- # or Windows Server 2008, i.e. major version 6, minor version 0.
218
- #
219
- def windows_vista?
220
- version = GetVersion()
221
- LOBYTE(LOWORD(version)) == 6 && HIBYTE(LOWORD(version)) == 0
222
- end
223
-
224
- def windows_7?
225
- version = GetVersion()
226
- LOBYTE(LOWORD(version)) == 6 && HIBYTE(LOWORD(version)) == 1
227
- end
228
- end
229
- end
1
+ require 'windows/api'
2
+
3
+ module Windows
4
+ module SystemInfo
5
+ API.auto_namespace = 'Windows::SystemInfo'
6
+ API.auto_constant = true
7
+ API.auto_method = true
8
+ API.auto_unicode = true
9
+
10
+ private
11
+
12
+ # Obsolete processor info constants
13
+
14
+ PROCESSOR_INTEL_386 = 386
15
+ PROCESSOR_INTEL_486 = 486
16
+ PROCESSOR_INTEL_PENTIUM = 586
17
+ PROCESSOR_INTEL_IA64 = 2200
18
+ PROCESSOR_AMD_X8664 = 8664
19
+
20
+ # Suite mask constants
21
+
22
+ VER_SERVER_NT = 0x80000000
23
+ VER_WORKSTATION_NT = 0x40000000
24
+ VER_SUITE_SMALLBUSINESS = 0x00000001
25
+ VER_SUITE_ENTERPRISE = 0x00000002
26
+ VER_SUITE_BACKOFFICE = 0x00000004
27
+ VER_SUITE_COMMUNICATIONS = 0x00000008
28
+ VER_SUITE_TERMINAL = 0x00000010
29
+ VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020
30
+ VER_SUITE_EMBEDDEDNT = 0x00000040
31
+ VER_SUITE_DATACENTER = 0x00000080
32
+ VER_SUITE_SINGLEUSERTS = 0x00000100
33
+ VER_SUITE_PERSONAL = 0x00000200
34
+ VER_SUITE_BLADE = 0x00000400
35
+ VER_SUITE_EMBEDDED_RESTRICTED = 0x00000800
36
+ VER_SUITE_SECURITY_APPLIANCE = 0x00001000
37
+ VER_SUITE_STORAGE_SERVER = 0x00002000
38
+ VER_SUITE_COMPUTE_SERVER = 0x00004000
39
+
40
+ # Product mask constants
41
+
42
+ VER_NT_WORKSTATION = 0x0000001
43
+ VER_NT_DOMAIN_CONTROLLER = 0x0000002
44
+ VER_NT_SERVER = 0x0000003
45
+
46
+ # Platform definitions
47
+
48
+ VER_PLATFORM_WIN32s = 0
49
+ VER_PLATFORM_WIN32_WINDOWS = 1
50
+ VER_PLATFORM_WIN32_NT = 2
51
+
52
+ # Version info type constants
53
+
54
+ VER_MINORVERSION = 0x0000001
55
+ VER_MAJORVERSION = 0x0000002
56
+ VER_BUILDNUMBER = 0x0000004
57
+ VER_PLATFORMID = 0x0000008
58
+ VER_SERVICEPACKMINOR = 0x0000010
59
+ VER_SERVICEPACKMAJOR = 0x0000020
60
+ VER_SUITENAME = 0x0000040
61
+ VER_PRODUCT_TYPE = 0x0000080
62
+
63
+ # Enum COMPUTER_NAME_FORMAT
64
+
65
+ ComputerNameNetBIOS = 0
66
+ ComputerNameDnsHostname = 1
67
+ ComputerNameDnsDomain = 2
68
+ ComputerNameDnsFullyQualified = 3
69
+ ComputerNamePhysicalNetBIOS = 4
70
+ ComputerNamePhysicalDnsHostname = 5
71
+ ComputerNamePhysicalDnsDomain = 6
72
+ ComputerNamePhysicalDnsFullyQualified = 7
73
+ ComputerNameMax = 8
74
+
75
+ API.new('ExpandEnvironmentStrings', 'PPL', 'L')
76
+ API.new('GetComputerName', 'PP', 'B')
77
+ API.new('GetComputerNameEx', 'PPP', 'B')
78
+ API.new('GetSystemInfo', 'P', 'V')
79
+ API.new('GetUserName', 'PP', 'B', 'advapi32')
80
+ API.new('GetUserNameEx', 'LPP', 'B', 'secur32')
81
+ API.new('GetVersion', 'V', 'L')
82
+ API.new('GetVersionEx', 'P', 'B')
83
+ API.new('GetWindowsDirectory', 'PI', 'I')
84
+
85
+ begin
86
+ API.new('GetSystemWow64Directory', 'PI', 'I')
87
+ rescue Win32::API::LoadLibraryError
88
+ # XP or later
89
+ end
90
+
91
+ # These macros are from windef.h, but I've put them here for now
92
+ # since they can be used in conjunction with some of the functions
93
+ # declared in this module.
94
+
95
+ def MAKEWORD(a, b)
96
+ ((a & 0xff) | ((b & 0xff) << 8))
97
+ end
98
+
99
+ def MAKELONG(a, b)
100
+ ((a & 0xffff) | ((b & 0xffff) << 16))
101
+ end
102
+
103
+ def LOWORD(l)
104
+ l & 0xffff
105
+ end
106
+
107
+ def HIWORD(l)
108
+ l >> 16
109
+ end
110
+
111
+ def LOBYTE(w)
112
+ w & 0xff
113
+ end
114
+
115
+ def HIBYTE(w)
116
+ w >> 8
117
+ end
118
+
119
+ # Returns a float indicating the major and minor version of Windows,
120
+ # e.g. 5.1, 6.0, etc.
121
+ #
122
+ def windows_version
123
+ version = GetVersion()
124
+ major = LOBYTE(LOWORD(version))
125
+ minor = HIBYTE(LOWORD(version))
126
+ eval("Float(#{major}.#{minor})")
127
+ end
128
+
129
+ # Custom methods that may come in handy
130
+
131
+ # Returns true if the current platform is Vista (any variant) or Windows
132
+ # Server 2008, i.e. major version 6, minor version 0.
133
+ #
134
+ def windows_2000?
135
+ version = GetVersion()
136
+ LOBYTE(LOWORD(version)) == 5 && HIBYTE(LOWORD(version)) == 0
137
+ end
138
+
139
+ # Returns true if the current platform is Windows XP or Windows XP
140
+ # Pro, i.e. major version 5, minor version 1 (or 2 in the case of a
141
+ # 64-bit Windows XP Pro).
142
+ #--
143
+ # Because of the exception for a 64-bit Windows XP Pro, we have to
144
+ # do things the hard way. For version 2 we look for any of the suite
145
+ # masks that might be associated with Windows 2003. If we don't find
146
+ # any of them, assume it's Windows XP.
147
+ #
148
+ def windows_xp?
149
+ bool = false
150
+
151
+ buf = 0.chr * 156
152
+ buf[0,4] = [buf.size].pack("L") # Set dwOSVersionInfoSize
153
+
154
+ GetVersionEx(buf)
155
+
156
+ major = buf[4,4].unpack("L")[0]
157
+ minor = buf[8,4].unpack("L")[0]
158
+ suite = buf[152,2].unpack("S")[0]
159
+
160
+ # Make sure we detect a 64-bit Windows XP Pro
161
+ if major == 5
162
+ if minor == 1
163
+ bool = true
164
+ elsif minor == 2
165
+ if (suite & VER_SUITE_BLADE == 0) &&
166
+ (suite & VER_SUITE_COMPUTE_SERVER == 0) &&
167
+ (suite & VER_SUITE_DATACENTER == 0) &&
168
+ (suite & VER_SUITE_ENTERPRISE == 0) &&
169
+ (suite & VER_SUITE_STORAGE_SERVER == 0)
170
+ then
171
+ bool = true
172
+ end
173
+ else
174
+ # Do nothing - already false
175
+ end
176
+ end
177
+
178
+ bool
179
+ end
180
+
181
+ # Returns true if the current platform is Windows 2003 (any version).
182
+ # i.e. major version 5, minor version 2.
183
+ #--
184
+ # Because of the exception for a 64-bit Windows XP Pro, we have to
185
+ # do things the hard way. For version 2 we look for any of the suite
186
+ # masks that might be associated with Windows 2003. If we find any
187
+ # of them, assume it's Windows 2003.
188
+ #
189
+ def windows_2003?
190
+ bool = false
191
+
192
+ buf = 0.chr * 156
193
+ buf[0,4] = [buf.size].pack("L") # Set dwOSVersionInfoSize
194
+
195
+ GetVersionEx(buf)
196
+
197
+ major = buf[4,4].unpack("L")[0]
198
+ minor = buf[8,4].unpack("L")[0]
199
+ suite = buf[152,2].unpack("S")[0]
200
+
201
+ # Make sure we exclude a 64-bit Windows XP Pro
202
+ if major == 5 && minor == 2
203
+ if (suite & VER_SUITE_BLADE > 0) ||
204
+ (suite & VER_SUITE_COMPUTE_SERVER > 0) ||
205
+ (suite & VER_SUITE_DATACENTER > 0) ||
206
+ (suite & VER_SUITE_ENTERPRISE > 0) ||
207
+ (suite & VER_SUITE_STORAGE_SERVER > 0)
208
+ then
209
+ bool = true
210
+ end
211
+ end
212
+
213
+ bool
214
+ end
215
+
216
+ # Returns true if the current platform is Windows Vista (any variant)
217
+ # or Windows Server 2008, i.e. major version 6, minor version 0.
218
+ #
219
+ def windows_vista?
220
+ version = GetVersion()
221
+ LOBYTE(LOWORD(version)) == 6 && HIBYTE(LOWORD(version)) == 0
222
+ end
223
+
224
+ def windows_7?
225
+ version = GetVersion()
226
+ LOBYTE(LOWORD(version)) == 6 && HIBYTE(LOWORD(version)) == 1
227
+ end
228
+ end
229
+ end