Advertisement
Guest User

Untitled

a guest
May 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.24 KB | None | 0 0
  1. BOOL GetOSDisplayString(LPTSTR pszOS)
  2. {
  3.     OSVERSIONINFOEX osvi;
  4.     SYSTEM_INFO si;
  5.     PGNSI pGNSI;
  6.     PGPI pGPI;
  7.     BOOL bOsVersionInfoEx;
  8.     DWORD dwType;
  9.  
  10.     SecureZeroMemory(&si, sizeof(SYSTEM_INFO));
  11.     SecureZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
  12.  
  13.     osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  14.     bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*)& osvi);
  15.  
  16.     if (!bOsVersionInfoEx) return 1;
  17.  
  18.     pGNSI = (PGNSI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
  19.     if (NULL != pGNSI)
  20.         pGNSI(&si);
  21.     else GetSystemInfo(&si);
  22.  
  23.  
  24.  
  25.     if (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId && osvi.dwMajorVersion > 4)
  26.     {
  27.         StringCchCopy(pszOS, BUFSIZE, TEXT("Microsoft "));
  28.  
  29.         if (IsWindows10OrGreater)
  30.         {
  31.             if (osvi.wProductType == VER_NT_WORKSTATION)
  32.             StringCchCat(pszOS, BUFSIZE, TEXT("Windows 10 "));
  33.         }
  34.  
  35.         else if(osvi.dwMajorVersion == 6)
  36.         {
  37.  
  38.             if (osvi.dwMinorVersion == 0)
  39.             {
  40.  
  41.                 if (osvi.wProductType == VER_NT_WORKSTATION)
  42.                     StringCchCat(pszOS, BUFSIZE, TEXT("Windows Vista "));
  43.                 else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2008 "));
  44.             }
  45.  
  46.             if (osvi.dwMinorVersion == 1 || osvi.dwMinorVersion == 2)
  47.             {
  48.                 if (osvi.wProductType == VER_NT_WORKSTATION && osvi.dwMinorVersion == 1)
  49.                     StringCchCat(pszOS, BUFSIZE, TEXT("Windows 7 "));
  50.                 else
  51.                     if (osvi.wProductType == VER_NT_WORKSTATION && osvi.dwMinorVersion == 2)
  52.                         StringCchCat(pszOS, BUFSIZE, TEXT("Windows 8 "));
  53.                     else
  54.                         StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2008 R2 "));
  55.             }
  56.  
  57.             pGPI = (PGPI)GetProcAddress(
  58.                 GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo");
  59.  
  60.             pGPI(osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);
  61.  
  62.             switch (dwType)
  63.             {
  64.             case PRODUCT_ULTIMATE:
  65.                 StringCchCat(pszOS, BUFSIZE, TEXT("Ultimate Edition"));
  66.                 break;
  67.             case PRODUCT_PROFESSIONAL:
  68.                 StringCchCat(pszOS, BUFSIZE, TEXT("Professional"));
  69.                 break;
  70.             case PRODUCT_HOME_PREMIUM:
  71.                 StringCchCat(pszOS, BUFSIZE, TEXT("Home Premium Edition"));
  72.                 break;
  73.             case PRODUCT_HOME_BASIC:
  74.                 StringCchCat(pszOS, BUFSIZE, TEXT("Home Basic Edition"));
  75.                 break;
  76.             case PRODUCT_ENTERPRISE:
  77.                 StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition"));
  78.                 break;
  79.             case PRODUCT_BUSINESS:
  80.                 StringCchCat(pszOS, BUFSIZE, TEXT("Business Edition"));
  81.                 break;
  82.             case PRODUCT_STARTER:
  83.                 StringCchCat(pszOS, BUFSIZE, TEXT("Starter Edition"));
  84.                 break;
  85.             case PRODUCT_CLUSTER_SERVER:
  86.                 StringCchCat(pszOS, BUFSIZE, TEXT("Cluster Server Edition"));
  87.                 break;
  88.             case PRODUCT_DATACENTER_SERVER:
  89.                 StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter Edition"));
  90.                 break;
  91.             case PRODUCT_DATACENTER_SERVER_CORE:
  92.                 StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter Edition (core installation)"));
  93.                 break;
  94.             case PRODUCT_ENTERPRISE_SERVER:
  95.                 StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition"));
  96.                 break;
  97.             case PRODUCT_ENTERPRISE_SERVER_CORE:
  98.                 StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition (core installation)"));
  99.                 break;
  100.             case PRODUCT_ENTERPRISE_SERVER_IA64:
  101.                 StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition for Itanium-based Systems"));
  102.                 break;
  103.             case PRODUCT_SMALLBUSINESS_SERVER:
  104.                 StringCchCat(pszOS, BUFSIZE, TEXT("Small Business Server"));
  105.                 break;
  106.             case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
  107.                 StringCchCat(pszOS, BUFSIZE, TEXT("Small Business Server Premium Edition"));
  108.                 break;
  109.             case PRODUCT_STANDARD_SERVER:
  110.                 StringCchCat(pszOS, BUFSIZE, TEXT("Standard Edition"));
  111.                 break;
  112.             case PRODUCT_STANDARD_SERVER_CORE:
  113.                 StringCchCat(pszOS, BUFSIZE, TEXT("Standard Edition (core installation)"));
  114.                 break;
  115.             case PRODUCT_WEB_SERVER:
  116.                 StringCchCat(pszOS, BUFSIZE, TEXT("Web Server Edition"));
  117.                 break;
  118.             }
  119.         }
  120.  
  121.         if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
  122.         {
  123.             if (GetSystemMetrics(SM_SERVERR2))
  124.                 StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2003 R2, "));
  125.             else if (osvi.wSuiteMask & VER_SUITE_STORAGE_SERVER)
  126.                 StringCchCat(pszOS, BUFSIZE, TEXT("Windows Storage Server 2003"));
  127.             else if (osvi.wSuiteMask & VER_SUITE_WH_SERVER)
  128.                 StringCchCat(pszOS, BUFSIZE, TEXT("Windows Home Server"));
  129.             else if (osvi.wProductType == VER_NT_WORKSTATION &&
  130.                 si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
  131.             {
  132.                 StringCchCat(pszOS, BUFSIZE, TEXT("Windows XP Professional x64 Edition"));
  133.             }
  134.             else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2003, "));
  135.  
  136.             if (osvi.wProductType != VER_NT_WORKSTATION)
  137.             {
  138.                 if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
  139.                 {
  140.                     if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
  141.                         StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter Edition for Itanium-based Systems"));
  142.                     else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
  143.                         StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition for Itanium-based Systems"));
  144.                 }
  145.  
  146.                 else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
  147.                 {
  148.                     if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
  149.                         StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter x64 Edition"));
  150.                     else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
  151.                         StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise x64 Edition"));
  152.                     else StringCchCat(pszOS, BUFSIZE, TEXT("Standard x64 Edition"));
  153.                 }
  154.  
  155.                 else
  156.                 {
  157.                     if (osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER)
  158.                         StringCchCat(pszOS, BUFSIZE, TEXT("Compute Cluster Edition"));
  159.                     else if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
  160.                         StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter Edition"));
  161.                     else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
  162.                         StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition"));
  163.                     else if (osvi.wSuiteMask & VER_SUITE_BLADE)
  164.                         StringCchCat(pszOS, BUFSIZE, TEXT("Web Edition"));
  165.                     else StringCchCat(pszOS, BUFSIZE, TEXT("Standard Edition"));
  166.                 }
  167.             }
  168.         }
  169.  
  170.         if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
  171.         {
  172.             StringCchCat(pszOS, BUFSIZE, TEXT("Windows XP "));
  173.             if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
  174.                 StringCchCat(pszOS, BUFSIZE, TEXT("Home Edition"));
  175.             else StringCchCat(pszOS, BUFSIZE, TEXT("Professional"));
  176.         }
  177.  
  178.         if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
  179.         {
  180.             StringCchCat(pszOS, BUFSIZE, TEXT("Windows 2000 "));
  181.  
  182.             if (osvi.wProductType == VER_NT_WORKSTATION)
  183.             {
  184.                 StringCchCat(pszOS, BUFSIZE, TEXT("Professional"));
  185.             }
  186.             else
  187.             {
  188.                 if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
  189.                     StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter Server"));
  190.                 else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
  191.                     StringCchCat(pszOS, BUFSIZE, TEXT("Advanced Server"));
  192.                 else StringCchCat(pszOS, BUFSIZE, TEXT("Server"));
  193.             }
  194.         }
  195.  
  196.         if (_tcslen(osvi.szCSDVersion) > 0)
  197.         {
  198.             StringCchCat(pszOS, BUFSIZE, TEXT(" "));
  199.             StringCchCat(pszOS, BUFSIZE, osvi.szCSDVersion);
  200.         }
  201.  
  202.         TCHAR buf[80];
  203.  
  204.         StringCchPrintf(buf, 80, TEXT(" (build %d)"), osvi.dwBuildNumber);
  205.         StringCchCat(pszOS, BUFSIZE, buf);
  206.  
  207.         if (osvi.dwMajorVersion >= 6)
  208.         {
  209.             if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
  210.                 StringCchCat(pszOS, BUFSIZE, TEXT(", 64-bit"));
  211.             else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
  212.                 StringCchCat(pszOS, BUFSIZE, TEXT(", 32-bit"));
  213.         }
  214.  
  215.         return TRUE;
  216.     }
  217.  
  218.     else
  219.     {
  220.         return FALSE;
  221.     }
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement