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

怎么用BCB6写出显示系统版本的程序

2013-11-05 
如何用BCB6写出显示系统版本的程序如何用BCB6写出显示系统版本的程序?需要用到什么函数?需显示的系统版本

如何用BCB6写出显示系统版本的程序
如何用BCB6写出显示系统版本的程序?需要用到什么函数?需显示的系统版本包括从WINXP到WIN8的系统。
[解决办法]
注册表里有相关信息,直接读取就行了。至于是在哪个键不记得了,搜搜看
[解决办法]

//开启 Regedit 至「HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion」查看值。
//---第一种方法 ---------------------------------
#include <Registry.hpp>

TRegistry *regOSBuild = new TRegistry;
String OSBuild;
try{
????regOSBuild -> RootKey = HKEY_LOCAL_MACHINE;
????regOSBuild -> OpenKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", false);
????OSBuild = regOSBuild -> ReadString("BuildLabEx"); //想读的值名称
????Label1 -> Caption = OSBuild;
???} __finally{
???????????????delete regOSBuild;
??????????????}
//---第二种方法 ---------------------------------
LPCTSTR lpRegPathNet = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
LPCTSTR lpRegValueNet = "BuildLabEx"; //想读的值名称
DWORD dwDataSizeNet(260);
DWORD dwRegTypeNet(REG_SZ);
LPBYTE lpRegBinDataNet = new char[512];
HKEY hKeyNet;
long lRetNet = (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRegPathNet, 0, KEY_READ, &hKeyNet));
if(lRetNet != ERROR_SUCCESS)
???return;
else{
?????lRetNet = (::RegQueryValueEx(hKeyNet, lpRegValueNet, NULL, &dwRegTypeNet,
?????????????????                             lpRegBinDataNet, &dwDataSizeNet));
?????Label1 -> Caption=String((char*)lpRegBinDataNet);
????} 
delete lpRegBinDataNet;
::RegCloseKey(hKeyNet);

[解决办法]
你不需要看懂,我已经封装好函数了,直接调用 CrnGetWindowsVersion 函数就行了。敢情我的例子也白写了?

void __fastcall TForm6::Button1Click(TObject *Sender)
{
    TCHAR lp[255];
    CrnGetWindowsVersion(lp);
    ShowMessage(lp);
}

[解决办法]
是的,这是较繁琐严谨一点可以针对OS去判断发行的版本。
对每个作业系统出的版本做细节判断,嫌代码长可以直接放在 if 外,
就行啦!如此只要每次判断完OS再去判断版本。
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;
                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;
    }
}

热点排行