首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

帮忙见见这段程序

2013-11-19 
帮忙看看这段程序[codec]BOOL CrnGetWindowsVersion(LPTSTR pszOS){OSVERSIONINFOEX osviSYSTEM_INFO si

帮忙看看这段程序
[code=c]
BOOL CrnGetWindowsVersion(LPTSTR pszOS)
{
    OSVERSIONINFOEX osvi;
    SYSTEM_INFO si;
    GETNATIVESYSTEMINFO pGNSI;
    GETPRODUCTINFO pGPI;
    BOOL bOsVersionInfoEx;
    DWORD dwType;

    ZeroMemory(&si, sizeof(SYSTEM_INFO));
    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

    bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi);
    if (!bOsVersionInfoEx)
        return 1;

    // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.

    pGNSI = (GETNATIVESYSTEMINFO)GetProcAddress(
            GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
    if (NULL != pGNSI)
        pGNSI(&si);
    else
        GetSystemInfo(&si);

    if (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId && osvi.dwMajorVersion > 4)
    {
        strncpy(pszOS, TEXT("Microsoft "), BUFSIZE);

        if(osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2)
              {
                     if(osvi.wProductType == VER_NT_WORKSTATION)
                        strcat(pszOS, TEXT("Windows 8 "));
                     else
                        strcat(pszOS, TEXT("Windows Server 2012 "));

                     pGPI = (GETPRODUCTINFO)GetProcAddress(
                             GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo");
                     if (pGPI)
                     {
                            pGPI(6, 2, 0, 0, &dwType);
                     }
              }
            if(osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1)
              {
                     if(osvi.wProductType == VER_NT_WORKSTATION)
                        strcat(pszOS, TEXT("Windows 7 "));
                     else
                        strcat(pszOS, TEXT("Windows Server 2008 R2 "));

                     pGPI = (GETPRODUCTINFO)GetProcAddress(
                             GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo");
                     if (pGPI)
                     {
                            pGPI(6, 1, 0, 0, &dwType);
                     }

               }


        // Test for the specific product.
        if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0)
        {
            if (osvi.wProductType == VER_NT_WORKSTATION)
                strcat(pszOS, TEXT("Windows Vista "));
            else
                strcat(pszOS, TEXT("Windows Server 2008 "));

            pGPI = (GETPRODUCTINFO)GetProcAddress(
                    GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo");
            if (pGPI)
            {
                pGPI(6, 0, 0, 0, &dwType);
            }
        }
 
        if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
        {
            if (GetSystemMetrics(SM_SERVERR2))
                strcat(pszOS, TEXT("Windows Server 2003 R2, "));
            else if (osvi.wSuiteMask == VER_SUITE_STORAGE_SERVER)
                strcat(pszOS, TEXT("Windows Storage Server 2003"));
            else if (osvi.wProductType == VER_NT_WORKSTATION
                    && si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
                strcat(pszOS, TEXT("Windows XP Professional x64 Edition"));
            else
                strcat(pszOS, TEXT("Windows Server 2003, "));

            // Test for the server type.
            if (osvi.wProductType != VER_NT_WORKSTATION)
            {
                if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
                {
                    if ((osvi.wSuiteMask & VER_SUITE_DATACENTER) == VER_SUITE_DATACENTER)
                        strcat(pszOS, TEXT("Datacenter Edition for Itanium-based Systems"));
                    else if ((osvi.wSuiteMask & VER_SUITE_ENTERPRISE) == VER_SUITE_ENTERPRISE)
                        strcat(pszOS, TEXT("Enterprise Edition for Itanium-based Systems"));
                }
                else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
                {
                    if ((osvi.wSuiteMask & VER_SUITE_DATACENTER) == VER_SUITE_DATACENTER)
                        strcat(pszOS, TEXT("Datacenter x64 Edition"));
                    else if ((osvi.wSuiteMask & VER_SUITE_ENTERPRISE) == VER_SUITE_ENTERPRISE)
                        strcat(pszOS, TEXT("Enterprise x64 Edition"));


                    else
                        strcat(pszOS, TEXT("Standard x64 Edition"));
                }
                else
                {
                    if ((osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER) == VER_SUITE_COMPUTE_SERVER)
                        strcat(pszOS, TEXT("Compute Cluster Edition"));
                    else if ((osvi.wSuiteMask & VER_SUITE_DATACENTER) == VER_SUITE_DATACENTER)
                        strcat(pszOS, TEXT("Datacenter Edition"));
                    else if ((osvi.wSuiteMask & VER_SUITE_ENTERPRISE) == VER_SUITE_ENTERPRISE)
                        strcat(pszOS, TEXT("Enterprise Edition"));
                    else if ((osvi.wSuiteMask & VER_SUITE_BLADE) == VER_SUITE_BLADE)
                        strcat(pszOS, TEXT("Web Edition"));
                    else
                        strcat(pszOS, TEXT("Standard Edition"));
                }
            }
        }
        if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
        {
            strcat(pszOS, TEXT("Windows XP "));
            if ((osvi.wSuiteMask & VER_SUITE_PERSONAL) == VER_SUITE_PERSONAL)
                strcat(pszOS, TEXT("Home Edition"));
            else
                strcat(pszOS, TEXT("Professional"));
        }
 
        if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
        {
            strcat(pszOS, TEXT("Windows 2000 "));
            if (osvi.wProductType == VER_NT_WORKSTATION)
            {
                strcat(pszOS, TEXT("Professional"));
            }
            else
            {
                if ((osvi.wSuiteMask & VER_SUITE_DATACENTER) == VER_SUITE_DATACENTER)
                    strcat(pszOS, TEXT("Datacenter Server"));
                else if ((osvi.wSuiteMask & VER_SUITE_ENTERPRISE) == VER_SUITE_ENTERPRISE)
                    strcat(pszOS, TEXT("Advanced Server"));
                else
                    strcat(pszOS, TEXT("Server"));
            }
        }
               switch (dwType)


            {
                case PRODUCT_ULTIMATE:
                    strcat(pszOS, TEXT("Ultimate Edition"));
                    break;
                case PRODUCT_HOME_PREMIUM:
                    strcat(pszOS, TEXT("Home Premium Edition"));
                    break;
                case PRODUCT_HOME_BASIC:
                    strcat(pszOS, TEXT("Home Basic Edition"));
                    break;
                case PRODUCT_ENTERPRISE:
                    strcat(pszOS, TEXT("Enterprise Edition"));
                    break;
                case PRODUCT_BUSINESS:
                    strcat(pszOS, TEXT("Business Edition"));
                    break;
                case PRODUCT_STARTER:
                    strcat(pszOS, TEXT("Starter Edition"));
                    break;
                case PRODUCT_CLUSTER_SERVER:
                    strcat(pszOS, TEXT("Cluster Server Edition"));
                    break;
                case PRODUCT_DATACENTER_SERVER:
                    strcat(pszOS, TEXT("Datacenter Edition"));
                    break;
                case PRODUCT_DATACENTER_SERVER_CORE:
                    strcat(pszOS, TEXT("Datacenter Edition (core installation)"));
                    break;
                case PRODUCT_ENTERPRISE_SERVER:
                    strcat(pszOS, TEXT("Enterprise Edition"));
                    break;
                case PRODUCT_ENTERPRISE_SERVER_CORE:
                    strcat(pszOS, TEXT("Enterprise Edition (core installation)"));
                    break;
                case PRODUCT_ENTERPRISE_SERVER_IA64:
                    strcat(pszOS, TEXT("Enterprise Edition for Itanium-based Systems"));
                    break;
                case PRODUCT_SMALLBUSINESS_SERVER:
                    strcat(pszOS, TEXT("Small Business Server"));
                    break;
                case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:


                    strcat(pszOS, TEXT("Small Business Server Premium Edition"));
                    break;
                case PRODUCT_STANDARD_SERVER:
                    strcat(pszOS, TEXT("Standard Edition"));
                    break;
                case PRODUCT_STANDARD_SERVER_CORE:
                    strcat(pszOS, TEXT("Standard Edition (core installation)"));
                    break;
                case PRODUCT_WEB_SERVER:
                    strcat(pszOS, TEXT("Web Server Edition"));
                    break;
                case PRODUCT_PROFESSIONAL:
                    strcat(pszOS, TEXT("Profession"));
                    break;
                default:
                    strcat(pszOS, TEXT("Unknown"));
                    break;
            }
            if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
                strcat(pszOS, TEXT(", 64-bit"));
            else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
                strcat(pszOS, TEXT(", 32-bit"));
        // Include service pack (if any) and build number.
        UINT uLen = strlen(osvi.szCSDVersion);
        if (uLen > 0)
        {
            strcat(pszOS, TEXT(" "));
            strcat(pszOS, osvi.szCSDVersion);
        }

        TCHAR szBuf[80];
        sprintf(szBuf, TEXT(" (build %d)"), osvi.dwBuildNumber);
        strcat(pszOS, szBuf);

        return TRUE;
    }
    else
    {
        MessageBox(0,
                TEXT("Does not support this version of Windows."),
                TEXT(__FUNC__),
                MB_ICONWARNING | MB_OK | MB_TASKMODAL | MB_SETFOREGROUND);

        return FALSE;
    }
}
在XP系统显示:Microsoft Windows XP ProfessionalUnknown, 32-bit Service Pack 3 (build 2600)
在WIN2003系统显示:Microsoft Windows Server 2003, Enterprise EditionUnknown, 32-bit Service Pack 2 (build 3790)
怎么会有Unknown
------解决方案--------------------


这能有啥弊端,这个unkonwn就是跟你说有个一版本无法确认是什么,你忽略它就好了

热点排行