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