276{
277
278
279 RTL_OSVERSIONINFOEXW osvi = { 0 };
280 osvi.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
281 NTSTATUS bVersionEx =
RtlGetVersion((PRTL_OSVERSIONINFOW)&osvi);
282 if (bVersionEx < 0)
283 {
284 osvi.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOW);
286 {
287 return FALSE;
288 }
289 }
290 *szVersion = _T('\0');
291
292 TCHAR szCSDVersion[256];
293 ToTchar(osvi.szCSDVersion, szCSDVersion, std::is_same<TCHAR, char>::type());
294
295 TCHAR wszTmp[128];
296 switch (osvi.dwPlatformId)
297 {
298
299 case VER_PLATFORM_WIN32_NT:
300 {
301#if WINVER < 0x0500
302 BYTE suiteMask = osvi.wReserved[0];
303 BYTE productType = osvi.wReserved[1];
304#else
305 WORD suiteMask = osvi.wSuiteMask;
306 BYTE productType = osvi.wProductType;
307#endif
308
309
310 if (osvi.dwMajorVersion == 10)
311 {
312 if (productType == VER_NT_WORKSTATION)
313 {
314 _tcsncat(szVersion, _T("Windows 10 "), cntMax);
315 }
316 else
317 {
318 _tcsncat(szVersion, _T("Windows Server 2016 "), cntMax);
319 }
320 }
321 else if (osvi.dwMajorVersion == 6)
322 {
323 if (productType == VER_NT_WORKSTATION)
324 {
325 if (osvi.dwMinorVersion == 3)
326 {
327 _tcsncat(szVersion, _T("Windows 8.1 "), cntMax);
328 }
329 else if (osvi.dwMinorVersion == 2)
330 {
331 _tcsncat(szVersion, _T("Windows 8 "), cntMax);
332 }
333 else if (osvi.dwMinorVersion == 1)
334 {
335 _tcsncat(szVersion, _T("Windows 7 "), cntMax);
336 }
337 else
338 {
339 _tcsncat(szVersion, _T("Windows Vista "), cntMax);
340 }
341 }
342 else if (osvi.dwMinorVersion == 3)
343 {
344 _tcsncat(szVersion, _T("Windows Server 2012 R2 "), cntMax);
345 }
346 else if (osvi.dwMinorVersion == 2)
347 {
348 _tcsncat(szVersion, _T("Windows Server 2012 "), cntMax);
349 }
350 else if (osvi.dwMinorVersion == 1)
351 {
352 _tcsncat(szVersion, _T("Windows Server 2008 R2 "), cntMax);
353 }
354 else
355 {
356 _tcsncat(szVersion, _T("Windows Server 2008 "), cntMax);
357 }
358 }
359 else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
360 {
361 _tcsncat(szVersion, _T("Microsoft Windows Server 2003 "), cntMax);
362 }
363 else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
364 {
365 _tcsncat(szVersion, _T("Microsoft Windows XP "), cntMax);
366 }
367 else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
368 {
369 _tcsncat(szVersion, _T("Microsoft Windows 2000 "), cntMax);
370 }
371 else if (osvi.dwMajorVersion <= 4)
372 {
373 _tcsncat(szVersion, _T("Microsoft Windows NT "), cntMax);
374 }
375
376
377 if (bVersionEx >= 0)
378 {
379
380 if (productType == VER_NT_WORKSTATION)
381 {
382 if (osvi.dwMajorVersion == 4)
383 {
384 _tcsncat(szVersion, _T("Workstation 4.0 "), cntMax);
385 }
386 else if (suiteMask & VER_SUITE_PERSONAL)
387 {
388 _tcsncat(szVersion, _T("Home Edition "), cntMax);
389 }
390 else if (suiteMask & VER_SUITE_EMBEDDEDNT)
391 {
392 _tcsncat(szVersion, _T("Embedded "), cntMax);
393 }
394 else
395 {
396 _tcsncat(szVersion, _T("Professional "), cntMax);
397 }
398 }
399
400 else if (productType == VER_NT_SERVER)
401 {
402 if (osvi.dwMajorVersion == 6 || osvi.dwMajorVersion == 10)
403 {
404 if (suiteMask & VER_SUITE_SMALLBUSINESS_RESTRICTED)
405 {
406 _tcsncat(szVersion, _T("Essentials "), cntMax);
407 }
408 else if (suiteMask & VER_SUITE_DATACENTER)
409 {
410 _tcsncat(szVersion, _T("Datacenter "), cntMax);
411 }
412 else if (suiteMask & VER_SUITE_ENTERPRISE)
413 {
414 _tcsncat(szVersion, _T("Enterprise "), cntMax);
415 }
416 else
417 {
418 _tcsncat(szVersion, _T("Standard "), cntMax);
419 }
420 }
421 else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
422 {
423 if (suiteMask & VER_SUITE_DATACENTER)
424 {
425 _tcsncat(szVersion, _T("Datacenter Edition "), cntMax);
426 }
427 else if (suiteMask & VER_SUITE_ENTERPRISE)
428 {
429 _tcsncat(szVersion, _T("Enterprise Edition "), cntMax);
430 }
431 else if (suiteMask == VER_SUITE_BLADE)
432 {
433 _tcsncat(szVersion, _T("Web Edition "), cntMax);
434 }
435 else
436 {
437 _tcsncat(szVersion, _T("Standard Edition "), cntMax);
438 }
439 }
440 else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
441 {
442 if (suiteMask & VER_SUITE_DATACENTER)
443 {
444 _tcsncat(szVersion, _T("Datacenter Server "), cntMax);
445 }
446 else if (suiteMask & VER_SUITE_ENTERPRISE)
447 {
448 _tcsncat(szVersion, _T("Advanced Server "), cntMax);
449 }
450 else
451 {
452 _tcsncat(szVersion, _T("Server "), cntMax);
453 }
454 }
455 else
456 {
457 if (suiteMask & VER_SUITE_ENTERPRISE)
458 {
459 _tcsncat(szVersion, _T("Server 4.0, Enterprise Edition "), cntMax);
460 }
461 else
462 {
463 _tcsncat(szVersion, _T("Server 4.0 "), cntMax);
464 }
465 }
466 }
467 }
468
469
470 if (osvi.dwMajorVersion == 4 && _tcsicmp(szCSDVersion, _T("Service Pack 6")) == 0)
471 {
472 HKEY hKey;
473 LONG lRet;
474
475
476 lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009"), 0, KEY_QUERY_VALUE, &hKey);
477 if (lRet == ERROR_SUCCESS)
478 {
479 _stprintf(wszTmp, _T("Service Pack 6a (Version %d.%d, Build %d)"),
480 osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF);
481 _tcsncat(szVersion, wszTmp, cntMax);
482 }
483 else
484 {
485 _stprintf(wszTmp, _T("%s (Version %d.%d, Build %d)"),
486 szCSDVersion, osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF);
487 _tcsncat(szVersion, wszTmp, cntMax);
488 }
489 ::RegCloseKey(hKey);
490 }
491 else
492 {
493 if (!_tcslen(szCSDVersion))
494 _stprintf(wszTmp, _T("(Version %d.%d, Build %d)"),
495 osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF);
496 else
497 _stprintf(wszTmp, _T("%s (Version %d.%d, Build %d)"),
498 szCSDVersion, osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF);
499 _tcsncat(szVersion, wszTmp, cntMax);
500 }
501 break;
502 }
503 default:
504 _stprintf(wszTmp, _T("%s (Version %d.%d, Build %d)"),
505 szCSDVersion, osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF);
506 _tcsncat(szVersion, wszTmp, cntMax);
507 break;
508 }
509
510 return TRUE;
511}
void ToTchar(wchar_t const *src, TCHAR(&dst)[size], std::true_type)
Definition: WheatyExceptionReport.cpp:264