1 | /* $Id: RTSystemQueryOSInfo-win.cpp 15954 2009-01-14 19:46:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - RTSystemQueryOSInfo, generic stub.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | *
|
---|
26 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 | /*******************************************************************************
|
---|
32 | * Header Files *
|
---|
33 | *******************************************************************************/
|
---|
34 | #include <Windows.h>
|
---|
35 | #include <WinUser.h>
|
---|
36 |
|
---|
37 | #include <iprt/system.h>
|
---|
38 | #include <iprt/assert.h>
|
---|
39 | #include <iprt/string.h>
|
---|
40 | #include <iprt/ctype.h>
|
---|
41 |
|
---|
42 |
|
---|
43 | /*******************************************************************************
|
---|
44 | * Structures and Typedefs *
|
---|
45 | *******************************************************************************/
|
---|
46 | /**
|
---|
47 | * Windows OS type as determined by rtSystemWinOSType().
|
---|
48 | */
|
---|
49 | typedef enum RTWINOSTYPE
|
---|
50 | {
|
---|
51 | kRTWinOSType_UNKNOWN = 0,
|
---|
52 | kRTWinOSType_9XFIRST = 1,
|
---|
53 | kRTWinOSType_95 = kRTWinOSType_9XFIRST,
|
---|
54 | kRTWinOSType_95SP1,
|
---|
55 | kRTWinOSType_95OSR2,
|
---|
56 | kRTWinOSType_98,
|
---|
57 | kRTWinOSType_98SP1,
|
---|
58 | kRTWinOSType_98SE,
|
---|
59 | kRTWinOSType_ME,
|
---|
60 | kRTWinOSType_9XLAST = 99,
|
---|
61 | kRTWinOSType_NTFIRST = 100,
|
---|
62 | kRTWinOSType_NT31 = kRTWinOSType_NTFIRST,
|
---|
63 | kRTWinOSType_NT351,
|
---|
64 | kRTWinOSType_NT4,
|
---|
65 | kRTWinOSType_2K,
|
---|
66 | kRTWinOSType_XP,
|
---|
67 | kRTWinOSType_2003,
|
---|
68 | kRTWinOSType_VISTA,
|
---|
69 | kRTWinOSType_2008,
|
---|
70 | kRTWinOSType_7,
|
---|
71 | kRTWinOSType_NT_UNKNOWN = 199,
|
---|
72 | kRTWinOSType_NT_LAST = kRTWinOSType_UNKNOWN
|
---|
73 | } RTWINOSTYPE;
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * These are the PRODUCT_* defines found in the Vista Platform SDK and returned
|
---|
77 | * by GetProductInfo().
|
---|
78 | *
|
---|
79 | * We define them ourselves because we don't necessarily have any Vista PSDK around.
|
---|
80 | */
|
---|
81 | typedef enum RTWINPRODTYPE
|
---|
82 | {
|
---|
83 | kRTWinProdType_UNDEFINED = 0x00000000, ///< An unknown product
|
---|
84 | kRTWinProdType_BUSINESS = 0x00000006, ///< Business Edition
|
---|
85 | kRTWinProdType_BUSINESS_N = 0x00000010, ///< Business Edition
|
---|
86 | kRTWinProdType_CLUSTER_SERVER = 0x00000012, ///< Cluster Server Edition
|
---|
87 | kRTWinProdType_DATACENTER_SERVER = 0x00000008, ///< Server Datacenter Edition (full installation)
|
---|
88 | kRTWinProdType_DATACENTER_SERVER_CORE = 0x0000000C, ///< Server Datacenter Edition (core installation)
|
---|
89 | kRTWinProdType_ENTERPRISE = 0x00000004, ///< Enterprise Edition
|
---|
90 | kRTWinProdType_ENTERPRISE_N = 0x0000001B, ///< Enterprise Edition
|
---|
91 | kRTWinProdType_ENTERPRISE_SERVER = 0x0000000A, ///< Server Enterprise Edition (full installation)
|
---|
92 | kRTWinProdType_ENTERPRISE_SERVER_CORE = 0x0000000E, ///< Server Enterprise Edition (core installation)
|
---|
93 | kRTWinProdType_ENTERPRISE_SERVER_IA64 = 0x0000000F, ///< Server Enterprise Edition for Itanium-based Systems
|
---|
94 | kRTWinProdType_HOME_BASIC = 0x00000002, ///< Home Basic Edition
|
---|
95 | kRTWinProdType_HOME_BASIC_N = 0x00000005, ///< Home Basic Edition
|
---|
96 | kRTWinProdType_HOME_PREMIUM = 0x00000003, ///< Home Premium Edition
|
---|
97 | kRTWinProdType_HOME_PREMIUM_N = 0x0000001A, ///< Home Premium Edition
|
---|
98 | kRTWinProdType_HOME_SERVER = 0x00000013, ///< Home Server Edition
|
---|
99 | kRTWinProdType_SERVER_FOR_SMALLBUSINESS = 0x00000018, ///< Server for Small Business Edition
|
---|
100 | kRTWinProdType_SMALLBUSINESS_SERVER = 0x00000009, ///< Small Business Server
|
---|
101 | kRTWinProdType_SMALLBUSINESS_SERVER_PREMIUM = 0x00000019, ///< Small Business Server Premium Edition
|
---|
102 | kRTWinProdType_STANDARD_SERVER = 0x00000007, ///< Server Standard Edition (full installation)
|
---|
103 | kRTWinProdType_STANDARD_SERVER_CORE = 0x0000000D, ///< Server Standard Edition (core installation)
|
---|
104 | kRTWinProdType_STARTER = 0x0000000B, ///< Starter Edition
|
---|
105 | kRTWinProdType_STORAGE_ENTERPRISE_SERVER = 0x00000017, ///< Storage Server Enterprise Edition
|
---|
106 | kRTWinProdType_STORAGE_EXPRESS_SERVER = 0x00000014, ///< Storage Server Express Edition
|
---|
107 | kRTWinProdType_STORAGE_STANDARD_SERVER = 0x00000015, ///< Storage Server Standard Edition
|
---|
108 | kRTWinProdType_STORAGE_WORKGROUP_SERVER = 0x00000016, ///< Storage Server Workgroup Edition
|
---|
109 | kRTWinProdType_ULTIMATE = 0x00000001, ///< Ultimate Edition
|
---|
110 | kRTWinProdType_ULTIMATE_N = 0x0000001C, ///< Ultimate Edition
|
---|
111 | kRTWinProdType_WEB_SERVER = 0x00000011, ///< Web Server Edition (full)
|
---|
112 | kRTWinProdType_WEB_SERVER_CORE = 0x0000001D ///< Web Server Edition (core)
|
---|
113 | } RTWINPRODTYPE;
|
---|
114 |
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Translates OSVERSIONINOFEX into a Windows OS type.
|
---|
118 | *
|
---|
119 | * @returns The Windows OS type.
|
---|
120 | * @param pOSInfoEx The OS info returned by Windows.
|
---|
121 | *
|
---|
122 | * @remarks This table has been assembled from Usenet postings, personal
|
---|
123 | * observations, and reading other people's code. Please feel
|
---|
124 | * free to add to it or correct it.
|
---|
125 | * <pre>
|
---|
126 | dwPlatFormID dwMajorVersion dwMinorVersion dwBuildNumber
|
---|
127 | 95 1 4 0 950
|
---|
128 | 95 SP1 1 4 0 >950 && <=1080
|
---|
129 | 95 OSR2 1 4 <10 >1080
|
---|
130 | 98 1 4 10 1998
|
---|
131 | 98 SP1 1 4 10 >1998 && <2183
|
---|
132 | 98 SE 1 4 10 >=2183
|
---|
133 | ME 1 4 90 3000
|
---|
134 |
|
---|
135 | NT 3.51 2 3 51 1057
|
---|
136 | NT 4 2 4 0 1381
|
---|
137 | 2000 2 5 0 2195
|
---|
138 | XP 2 5 1 2600
|
---|
139 | 2003 2 5 2 3790
|
---|
140 | Vista 2 6 0
|
---|
141 |
|
---|
142 | CE 1.0 3 1 0
|
---|
143 | CE 2.0 3 2 0
|
---|
144 | CE 2.1 3 2 1
|
---|
145 | CE 3.0 3 3 0
|
---|
146 | </pre>
|
---|
147 | */
|
---|
148 | static RTWINOSTYPE rtSystemWinOSType(OSVERSIONINFOEX const *pOSInfoEx)
|
---|
149 | {
|
---|
150 | RTWINOSTYPE enmVer = kRTWinOSType_UNKNOWN;
|
---|
151 | BYTE const bProductType = pOSInfoEx->wProductType;
|
---|
152 | DWORD const dwPlatformId = pOSInfoEx->dwPlatformId;
|
---|
153 | DWORD const dwMinorVersion = pOSInfoEx->dwMinorVersion;
|
---|
154 | DWORD const dwMajorVersion = pOSInfoEx->dwMajorVersion;
|
---|
155 | DWORD const dwBuildNumber = pOSInfoEx->dwBuildNumber & 0xFFFF; /* Win 9x needs this. */
|
---|
156 |
|
---|
157 | if ( dwPlatformId == VER_PLATFORM_WIN32_WINDOWS
|
---|
158 | && dwMajorVersion == 4)
|
---|
159 | {
|
---|
160 | if ( dwMinorVersion < 10
|
---|
161 | && dwBuildNumber == 950)
|
---|
162 | enmVer = kRTWinOSType_95;
|
---|
163 | else if ( dwMinorVersion < 10
|
---|
164 | && dwBuildNumber > 950
|
---|
165 | && dwBuildNumber <= 1080)
|
---|
166 | enmVer = kRTWinOSType_95SP1;
|
---|
167 | else if ( dwMinorVersion < 10
|
---|
168 | && dwBuildNumber > 1080)
|
---|
169 | enmVer = kRTWinOSType_95OSR2;
|
---|
170 | else if ( dwMinorVersion == 10
|
---|
171 | && dwBuildNumber == 1998)
|
---|
172 | enmVer = kRTWinOSType_98;
|
---|
173 | else if ( dwMinorVersion == 10
|
---|
174 | && dwBuildNumber > 1998
|
---|
175 | && dwBuildNumber < 2183)
|
---|
176 | enmVer = kRTWinOSType_98SP1;
|
---|
177 | else if ( dwMinorVersion == 10
|
---|
178 | && dwBuildNumber >= 2183)
|
---|
179 | enmVer = kRTWinOSType_98SE;
|
---|
180 | else if (dwMinorVersion == 90)
|
---|
181 | enmVer = kRTWinOSType_ME;
|
---|
182 | }
|
---|
183 | else if (dwPlatformId == VER_PLATFORM_WIN32_NT)
|
---|
184 | {
|
---|
185 | if ( dwMajorVersion == 3
|
---|
186 | && dwMinorVersion == 51)
|
---|
187 | enmVer = kRTWinOSType_NT351;
|
---|
188 | else if ( dwMajorVersion == 4
|
---|
189 | && dwMinorVersion == 0)
|
---|
190 | enmVer = kRTWinOSType_NT4;
|
---|
191 | else if ( dwMajorVersion == 5
|
---|
192 | && dwMinorVersion == 0)
|
---|
193 | enmVer = kRTWinOSType_2K;
|
---|
194 | else if ( dwMajorVersion == 5
|
---|
195 | && dwMinorVersion == 1)
|
---|
196 | enmVer = kRTWinOSType_XP;
|
---|
197 | else if ( dwMajorVersion == 5
|
---|
198 | && dwMinorVersion == 2)
|
---|
199 | enmVer = kRTWinOSType_2003;
|
---|
200 | else if ( dwMajorVersion == 6
|
---|
201 | && dwMinorVersion == 0)
|
---|
202 | {
|
---|
203 | if (bProductType != VER_NT_WORKSTATION)
|
---|
204 | enmVer = kRTWinOSType_2008;
|
---|
205 | else
|
---|
206 | enmVer = kRTWinOSType_VISTA;
|
---|
207 | }
|
---|
208 | else if ( dwMajorVersion == 6
|
---|
209 | && dwMinorVersion == 1)
|
---|
210 | enmVer = kRTWinOSType_7;
|
---|
211 | else
|
---|
212 | enmVer = kRTWinOSType_NT_UNKNOWN;
|
---|
213 | }
|
---|
214 |
|
---|
215 | return enmVer;
|
---|
216 | }
|
---|
217 |
|
---|
218 |
|
---|
219 | /**
|
---|
220 | * Wrapper around the GetProductInfo API.
|
---|
221 | *
|
---|
222 | * @returns The vista type.
|
---|
223 | */
|
---|
224 | static RTWINPRODTYPE rtSystemWinGetProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion, DWORD dwSpMinorVersion)
|
---|
225 | {
|
---|
226 | BOOL (WINAPI *pfnGetProductInfo)(DWORD, DWORD, DWORD, DWORD, PDWORD);
|
---|
227 | pfnGetProductInfo = (BOOL (WINAPI *)(DWORD, DWORD, DWORD, DWORD, PDWORD))GetProcAddress(GetModuleHandle("KERNEL32.DLL"), "GetProductInfo");
|
---|
228 | if (pfnGetProductInfo)
|
---|
229 | {
|
---|
230 | DWORD dwProductType = kRTWinProdType_UNDEFINED;
|
---|
231 | if (pfnGetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion, &dwProductType))
|
---|
232 | return (RTWINPRODTYPE)dwProductType;
|
---|
233 | }
|
---|
234 | return kRTWinProdType_UNDEFINED;
|
---|
235 | }
|
---|
236 |
|
---|
237 |
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Appends the product type if available.
|
---|
241 | *
|
---|
242 | * @param pszTmp The buffer. Assumes it's big enough.
|
---|
243 | */
|
---|
244 | static void rtSystemWinAppendProductType(char *pszTmp)
|
---|
245 | {
|
---|
246 | RTWINPRODTYPE enmVistaType = rtSystemWinGetProductInfo(6, 0, 0, 0);
|
---|
247 | switch (enmVistaType)
|
---|
248 | {
|
---|
249 | case kRTWinProdType_BUSINESS: strcat(pszTmp, " Business Edition"); break;
|
---|
250 | case kRTWinProdType_BUSINESS_N: strcat(pszTmp, " Business Edition"); break;
|
---|
251 | case kRTWinProdType_CLUSTER_SERVER: strcat(pszTmp, " Cluster Server Edition"); break;
|
---|
252 | case kRTWinProdType_DATACENTER_SERVER: strcat(pszTmp, " Server Datacenter Edition (full installation)"); break;
|
---|
253 | case kRTWinProdType_DATACENTER_SERVER_CORE: strcat(pszTmp, " Server Datacenter Edition (core installation)"); break;
|
---|
254 | case kRTWinProdType_ENTERPRISE: strcat(pszTmp, " Enterprise Edition"); break;
|
---|
255 | case kRTWinProdType_ENTERPRISE_N: strcat(pszTmp, " Enterprise Edition"); break;
|
---|
256 | case kRTWinProdType_ENTERPRISE_SERVER: strcat(pszTmp, " Server Enterprise Edition (full installation)"); break;
|
---|
257 | case kRTWinProdType_ENTERPRISE_SERVER_CORE: strcat(pszTmp, " Server Enterprise Edition (core installation)"); break;
|
---|
258 | case kRTWinProdType_ENTERPRISE_SERVER_IA64: strcat(pszTmp, " Server Enterprise Edition for Itanium-based Systems"); break;
|
---|
259 | case kRTWinProdType_HOME_BASIC: strcat(pszTmp, " Home Basic Edition"); break;
|
---|
260 | case kRTWinProdType_HOME_BASIC_N: strcat(pszTmp, " Home Basic Edition"); break;
|
---|
261 | case kRTWinProdType_HOME_PREMIUM: strcat(pszTmp, " Home Premium Edition"); break;
|
---|
262 | case kRTWinProdType_HOME_PREMIUM_N: strcat(pszTmp, " Home Premium Edition"); break;
|
---|
263 | case kRTWinProdType_HOME_SERVER: strcat(pszTmp, " Home Server Edition"); break;
|
---|
264 | case kRTWinProdType_SERVER_FOR_SMALLBUSINESS: strcat(pszTmp, " Server for Small Business Edition"); break;
|
---|
265 | case kRTWinProdType_SMALLBUSINESS_SERVER: strcat(pszTmp, " Small Business Server"); break;
|
---|
266 | case kRTWinProdType_SMALLBUSINESS_SERVER_PREMIUM: strcat(pszTmp, " Small Business Server Premium Edition"); break;
|
---|
267 | case kRTWinProdType_STANDARD_SERVER: strcat(pszTmp, " Server Standard Edition (full installation)"); break;
|
---|
268 | case kRTWinProdType_STANDARD_SERVER_CORE: strcat(pszTmp, " Server Standard Edition (core installation)"); break;
|
---|
269 | case kRTWinProdType_STARTER: strcat(pszTmp, " Starter Edition"); break;
|
---|
270 | case kRTWinProdType_STORAGE_ENTERPRISE_SERVER: strcat(pszTmp, " Storage Server Enterprise Edition"); break;
|
---|
271 | case kRTWinProdType_STORAGE_EXPRESS_SERVER: strcat(pszTmp, " Storage Server Express Edition"); break;
|
---|
272 | case kRTWinProdType_STORAGE_STANDARD_SERVER: strcat(pszTmp, " Storage Server Standard Edition"); break;
|
---|
273 | case kRTWinProdType_STORAGE_WORKGROUP_SERVER: strcat(pszTmp, " Storage Server Workgroup Edition"); break;
|
---|
274 | case kRTWinProdType_ULTIMATE: strcat(pszTmp, " Ultimate Edition"); break;
|
---|
275 | case kRTWinProdType_ULTIMATE_N: strcat(pszTmp, " Ultimate Edition"); break;
|
---|
276 | case kRTWinProdType_WEB_SERVER: strcat(pszTmp, " Web Server Edition (full installation)"); break;
|
---|
277 | case kRTWinProdType_WEB_SERVER_CORE: strcat(pszTmp, " Web Server Edition (core installation)"); break;
|
---|
278 | case kRTWinProdType_UNDEFINED: break;
|
---|
279 | }
|
---|
280 | }
|
---|
281 |
|
---|
282 |
|
---|
283 | /**
|
---|
284 | * Services the RTSYSOSINFO_PRODUCT, RTSYSOSINFO_RELEASE
|
---|
285 | * and RTSYSOSINFO_SERVICE_PACK requests.
|
---|
286 | *
|
---|
287 | * @returns See RTSystemQueryOSInfo.
|
---|
288 | * @param enmInfo See RTSystemQueryOSInfo.
|
---|
289 | * @param pszInfo See RTSystemQueryOSInfo.
|
---|
290 | * @param cchInfo See RTSystemQueryOSInfo.
|
---|
291 | */
|
---|
292 | static int rtSystemWinQueryOSVersion(RTSYSOSINFO enmInfo, char *pszInfo, size_t cchInfo)
|
---|
293 | {
|
---|
294 | int rc;
|
---|
295 |
|
---|
296 | /*
|
---|
297 | * Make sure it's terminated correctly in case of error.
|
---|
298 | */
|
---|
299 | *pszInfo = '\0';
|
---|
300 |
|
---|
301 | /*
|
---|
302 | * Query the Windows version.
|
---|
303 | *
|
---|
304 | * ASSUMES OSVERSIONINFOEX starts with the exact same layout as OSVERSIONINFO (safe).
|
---|
305 | */
|
---|
306 | OSVERSIONINFOEX OSInfoEx;
|
---|
307 | memset(&OSInfoEx, '\0', sizeof(OSInfoEx));
|
---|
308 | OSInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
---|
309 | if (!GetVersionEx((LPOSVERSIONINFO) &OSInfoEx))
|
---|
310 | {
|
---|
311 | DWORD err = GetLastError();
|
---|
312 | rc = RTErrConvertFromWin32(err);
|
---|
313 | AssertMsgFailedReturn(("err=%d\n", err), rc == VERR_BUFFER_OVERFLOW ? VERR_INTERNAL_ERROR : rc);
|
---|
314 | }
|
---|
315 |
|
---|
316 | /* Get extended version info for 2000 and later. */
|
---|
317 | if ( OSInfoEx.dwPlatformId == VER_PLATFORM_WIN32_NT
|
---|
318 | && OSInfoEx.dwMajorVersion >= 5)
|
---|
319 | {
|
---|
320 | ZeroMemory(&OSInfoEx, sizeof(OSInfoEx));
|
---|
321 | OSInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
---|
322 | if (!GetVersionEx((LPOSVERSIONINFO) &OSInfoEx))
|
---|
323 | {
|
---|
324 | DWORD err = GetLastError();
|
---|
325 | rc = RTErrConvertFromWin32(err);
|
---|
326 | AssertMsgFailedReturn(("err=%d\n", err), rc == VERR_BUFFER_OVERFLOW ? VERR_INTERNAL_ERROR : rc);
|
---|
327 | }
|
---|
328 | }
|
---|
329 |
|
---|
330 | /*
|
---|
331 | * Service the request.
|
---|
332 | */
|
---|
333 | char szTmp[512];
|
---|
334 | szTmp[0] = '\0';
|
---|
335 | rc = VINF_SUCCESS;
|
---|
336 | switch (enmInfo)
|
---|
337 | {
|
---|
338 | /*
|
---|
339 | * The product name.
|
---|
340 | */
|
---|
341 | case RTSYSOSINFO_PRODUCT:
|
---|
342 | {
|
---|
343 | RTWINOSTYPE enmVer = rtSystemWinOSType(&OSInfoEx);
|
---|
344 | switch (enmVer)
|
---|
345 | {
|
---|
346 | case kRTWinOSType_95: strcpy(szTmp, "Windows 95"); break;
|
---|
347 | case kRTWinOSType_95SP1: strcpy(szTmp, "Windows 95 (Service Pack 1)"); break;
|
---|
348 | case kRTWinOSType_95OSR2: strcpy(szTmp, "Windows 95 (OSR 2)"); break;
|
---|
349 | case kRTWinOSType_98: strcpy(szTmp, "Windows 98"); break;
|
---|
350 | case kRTWinOSType_98SP1: strcpy(szTmp, "Windows 98 (Service Pack 1)"); break;
|
---|
351 | case kRTWinOSType_98SE: strcpy(szTmp, "Windows 98 (Second Edition)"); break;
|
---|
352 | case kRTWinOSType_ME: strcpy(szTmp, "Windows Me"); break;
|
---|
353 | case kRTWinOSType_NT351: strcpy(szTmp, "Windows NT 3.51"); break;
|
---|
354 | case kRTWinOSType_NT4: strcpy(szTmp, "Windows NT 4.0"); break;
|
---|
355 | case kRTWinOSType_2K: strcpy(szTmp, "Windows 2000"); break;
|
---|
356 | case kRTWinOSType_XP:
|
---|
357 | strcpy(szTmp, "Windows XP");
|
---|
358 | if (OSInfoEx.wSuiteMask & VER_SUITE_PERSONAL)
|
---|
359 | strcat(szTmp, " Home");
|
---|
360 | if ( OSInfoEx.wProductType == VER_NT_WORKSTATION
|
---|
361 | && !(OSInfoEx.wSuiteMask & VER_SUITE_PERSONAL))
|
---|
362 | strcat(szTmp, " Professional");
|
---|
363 | #if 0 /** @todo fixme */
|
---|
364 | if (GetSystemMetrics(SM_MEDIACENTER))
|
---|
365 | strcat(szTmp, " Media Center");
|
---|
366 | #endif
|
---|
367 | break;
|
---|
368 |
|
---|
369 | case kRTWinOSType_2003: strcpy(szTmp, "Windows 2003"); break;
|
---|
370 | case kRTWinOSType_VISTA:
|
---|
371 | {
|
---|
372 | strcpy(szTmp, "Windows Vista");
|
---|
373 | rtSystemWinAppendProductType(szTmp);
|
---|
374 | break;
|
---|
375 | }
|
---|
376 | case kRTWinOSType_2008: strcpy(szTmp, "Windows 2008"); break;
|
---|
377 | case kRTWinOSType_7: strcpy(szTmp, "Windows 7"); break;
|
---|
378 |
|
---|
379 | case kRTWinOSType_NT_UNKNOWN:
|
---|
380 | RTStrPrintf(szTmp, sizeof(szTmp), "Unknown NT v%u.%u", OSInfoEx.dwMajorVersion, OSInfoEx.dwMinorVersion);
|
---|
381 | break;
|
---|
382 |
|
---|
383 | default:
|
---|
384 | AssertFailed();
|
---|
385 | case kRTWinOSType_UNKNOWN:
|
---|
386 | RTStrPrintf(szTmp, sizeof(szTmp), "Unknown %d v%u.%u", OSInfoEx.dwPlatformId, OSInfoEx.dwMajorVersion, OSInfoEx.dwMinorVersion);
|
---|
387 | break;
|
---|
388 | }
|
---|
389 | break;
|
---|
390 | }
|
---|
391 |
|
---|
392 | /*
|
---|
393 | * The release.
|
---|
394 | */
|
---|
395 | case RTSYSOSINFO_RELEASE:
|
---|
396 | {
|
---|
397 | RTWINOSTYPE enmVer = rtSystemWinOSType(&OSInfoEx);
|
---|
398 | RTStrPrintf(szTmp, sizeof(szTmp), "%u.%u.%u", OSInfoEx.dwMajorVersion, OSInfoEx.dwMinorVersion, OSInfoEx.dwBuildNumber);
|
---|
399 | break;
|
---|
400 | }
|
---|
401 |
|
---|
402 |
|
---|
403 | /*
|
---|
404 | * Get the service pack.
|
---|
405 | */
|
---|
406 | case RTSYSOSINFO_SERVICE_PACK:
|
---|
407 | {
|
---|
408 | if (OSInfoEx.wServicePackMajor)
|
---|
409 | {
|
---|
410 | if (OSInfoEx.wServicePackMinor)
|
---|
411 | RTStrPrintf(szTmp, sizeof(szTmp), "%u.%u", (unsigned)OSInfoEx.wServicePackMajor, (unsigned)OSInfoEx.wServicePackMinor);
|
---|
412 | else
|
---|
413 | RTStrPrintf(szTmp, sizeof(szTmp), "%u", (unsigned)OSInfoEx.wServicePackMajor);
|
---|
414 | }
|
---|
415 | else if (OSInfoEx.szCSDVersion[0])
|
---|
416 | {
|
---|
417 | /* just copy the entire string. */
|
---|
418 | memcpy(szTmp, OSInfoEx.szCSDVersion, sizeof(OSInfoEx.szCSDVersion));
|
---|
419 | szTmp[sizeof(OSInfoEx.szCSDVersion)] = '\0';
|
---|
420 | AssertCompile(sizeof(szTmp) > sizeof(OSInfoEx.szCSDVersion));
|
---|
421 | }
|
---|
422 | else
|
---|
423 | {
|
---|
424 | RTWINOSTYPE enmVer = rtSystemWinOSType(&OSInfoEx);
|
---|
425 | switch (enmVer)
|
---|
426 | {
|
---|
427 | case kRTWinOSType_95SP1: strcpy(szTmp, "1"); break;
|
---|
428 | case kRTWinOSType_98SP1: strcpy(szTmp, "1"); break;
|
---|
429 | default:
|
---|
430 | break;
|
---|
431 | }
|
---|
432 | }
|
---|
433 | break;
|
---|
434 | }
|
---|
435 |
|
---|
436 | default:
|
---|
437 | AssertFatalFailed();
|
---|
438 | }
|
---|
439 |
|
---|
440 | /*
|
---|
441 | * Copy the result to the return buffer.
|
---|
442 | */
|
---|
443 | size_t cchTmp = strlen(szTmp);
|
---|
444 | Assert(cchTmp < sizeof(szTmp));
|
---|
445 | if (cchTmp < cchInfo)
|
---|
446 | memcpy(pszInfo, szTmp, cchTmp + 1);
|
---|
447 | else
|
---|
448 | {
|
---|
449 | memcpy(pszInfo, szTmp, cchInfo - 1);
|
---|
450 | pszInfo[cchInfo - 1] = '\0';
|
---|
451 | if (RT_SUCCESS(rc))
|
---|
452 | rc = VERR_BUFFER_OVERFLOW;
|
---|
453 | }
|
---|
454 | return VINF_SUCCESS;
|
---|
455 | }
|
---|
456 |
|
---|
457 |
|
---|
458 |
|
---|
459 | RTDECL(int) RTSystemQueryOSInfo(RTSYSOSINFO enmInfo, char *pszInfo, size_t cchInfo)
|
---|
460 | {
|
---|
461 | /*
|
---|
462 | * Quick validation.
|
---|
463 | */
|
---|
464 | AssertReturn(enmInfo > RTSYSOSINFO_INVALID && enmInfo < RTSYSOSINFO_END, VERR_INVALID_PARAMETER);
|
---|
465 | AssertPtrReturn(pszInfo, VERR_INVALID_POINTER);
|
---|
466 | if (!cchInfo)
|
---|
467 | return VERR_BUFFER_OVERFLOW;
|
---|
468 |
|
---|
469 |
|
---|
470 | /*
|
---|
471 | * Handle the request.
|
---|
472 | */
|
---|
473 | switch (enmInfo)
|
---|
474 | {
|
---|
475 | case RTSYSOSINFO_PRODUCT:
|
---|
476 | case RTSYSOSINFO_RELEASE:
|
---|
477 | case RTSYSOSINFO_SERVICE_PACK:
|
---|
478 | return rtSystemWinQueryOSVersion(enmInfo, pszInfo, cchInfo);
|
---|
479 |
|
---|
480 | case RTSYSOSINFO_VERSION:
|
---|
481 | default:
|
---|
482 | *pszInfo = '\0';
|
---|
483 | return VERR_NOT_SUPPORTED;
|
---|
484 | }
|
---|
485 | }
|
---|
486 |
|
---|
487 |
|
---|
488 |
|
---|