qt 获取win操作系统版本信息

bool GetOSDisplayString( QString& pszOS){OSVERSIONINFOEX osvi;SYSTEM_INFO si;PGNSI pGNSI;PGPI pGPI;BOOL bOsVersionInfoEx;DWORD dwType;ZeroMemory(&si, sizeof(SYSTEM_INFO));ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )return 1;// Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");if(NULL != pGNSI)pGNSI(&si);else GetSystemInfo(&si);if ( VER_PLATFORM_WIN32_NT==osvi.dwPlatformId && osvi.dwMajorVersion > 4 ){pszOS = "Microsoft ";// Test for the specific product.if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 ){if( osvi.wProductType == VER_NT_WORKSTATION )pszOS +="Windows Vista ";else pszOS +="Windows Server 2008 ";pGPI = (PGPI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo");pGPI( 6, 0, 0, 0, &dwType);switch( dwType ){case PRODUCT_ULTIMATE:pszOS +="Ultimate Edition" ;break;case PRODUCT_HOME_PREMIUM:pszOS +="Home Premium Edition" ;break;case PRODUCT_HOME_BASIC:pszOS +="Home Basic Edition" ;break;case PRODUCT_ENTERPRISE:pszOS +="Enterprise Edition" ;break;case PRODUCT_BUSINESS:pszOS +="Business Edition" ;break;case PRODUCT_STARTER:pszOS +="Starter Edition" ;break;case PRODUCT_CLUSTER_SERVER:pszOS +="Cluster Server Edition" ;break;case PRODUCT_DATACENTER_SERVER:pszOS +="Datacenter Edition" ;break;case PRODUCT_DATACENTER_SERVER_CORE:pszOS +="Datacenter Edition (core installation)";break;case PRODUCT_ENTERPRISE_SERVER:pszOS +="Enterprise Edition" ;break;case PRODUCT_ENTERPRISE_SERVER_CORE:pszOS +="Enterprise Edition (core installation)" ;break;case PRODUCT_ENTERPRISE_SERVER_IA64:pszOS +="Enterprise Edition for Itanium-based Systems" ;break;case PRODUCT_SMALLBUSINESS_SERVER:pszOS +="Small Business Server" ;break;case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:pszOS +="Small Business Server Premium Edition" ;break;case PRODUCT_STANDARD_SERVER:pszOS +="Standard Edition" ;break;case PRODUCT_STANDARD_SERVER_CORE:pszOS +="Standard Edition (core installation)" ;break;case PRODUCT_WEB_SERVER:pszOS +="Web Server Edition";break;}if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )pszOS += ", 64-bit" ;else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL )pszOS +=", 32-bit";}if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1 ){if( osvi.wProductType == VER_NT_WORKSTATION )pszOS +="Windows 7 ";else pszOS +="Windows Server 2008 R2 ";pGPI = (PGPI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo");pGPI( 6, 0, 0, 0, &dwType);switch( dwType ){case PRODUCT_ULTIMATE:pszOS +="Ultimate Edition" ;break;case PRODUCT_HOME_PREMIUM:pszOS +="Home Premium Edition" ;break;case PRODUCT_HOME_BASIC:pszOS +="Home Basic Edition" ;break;case PRODUCT_ENTERPRISE:pszOS +="Enterprise Edition" ;break;case PRODUCT_BUSINESS:pszOS +="Business Edition" ;break;case PRODUCT_STARTER:pszOS +="Starter Edition" ;break;case PRODUCT_CLUSTER_SERVER:pszOS +="Cluster Server Edition" ;break;case PRODUCT_DATACENTER_SERVER:pszOS +="Datacenter Edition" ;break;case PRODUCT_DATACENTER_SERVER_CORE:pszOS +="Datacenter Edition (core installation)";break;case PRODUCT_ENTERPRISE_SERVER:pszOS +="Enterprise Edition" ;break;case PRODUCT_ENTERPRISE_SERVER_CORE:pszOS +="Enterprise Edition (core installation)" ;break;case PRODUCT_ENTERPRISE_SERVER_IA64:pszOS +="Enterprise Edition for Itanium-based Systems" ;break;case PRODUCT_SMALLBUSINESS_SERVER:pszOS +="Small Business Server" ;break;case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:pszOS +="Small Business Server Premium Edition" ;break;case PRODUCT_STANDARD_SERVER:pszOS +="Standard Edition" ;break;case PRODUCT_STANDARD_SERVER_CORE:pszOS +="Standard Edition (core installation)" ;break;case PRODUCT_WEB_SERVER:pszOS +="Web Server Edition";break;}if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )pszOS += ", 64-bit" ;else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL )pszOS +=", 32-bit";}if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ){if( GetSystemMetrics(SM_SERVERR2) )pszOS += "Windows Server 2003 R2, ";else if ( osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER )pszOS +="Windows Storage Server 2003";else if( osvi.wProductType == VER_NT_WORKSTATION &&si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64){pszOS += "Windows XP Professional x64 Edition";}else pszOS +="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 )pszOS +="Datacenter Edition for Itanium-based Systems" ;else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )pszOS += "Enterprise Edition for Itanium-based Systems";}else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 ){if( osvi.wSuiteMask & VER_SUITE_DATACENTER )pszOS += "Datacenter x64 Edition" ;else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )pszOS += "Enterprise x64 Edition" ;else pszOS += "Standard x64 Edition";}else{if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )pszOS += "Compute Cluster Edition" ;else if( osvi.wSuiteMask & VER_SUITE_DATACENTER )pszOS += "Datacenter Edition";else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )pszOS +="Enterprise Edition" ;else if ( osvi.wSuiteMask & VER_SUITE_BLADE )pszOS += "Web Edition" ;else pszOS +="Standard Edition" ;}}}if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ){pszOS +="Windows XP ";if( osvi.wSuiteMask & VER_SUITE_PERSONAL )pszOS += "Home Edition" ;else pszOS +="Professional" ;}if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ){pszOS +="Windows 2000 ";if ( osvi.wProductType == VER_NT_WORKSTATION ){pszOS += "Professional" ;}else {if( osvi.wSuiteMask & VER_SUITE_DATACENTER )pszOS += "Datacenter Server" ;else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )pszOS +="Advanced Server" ;else pszOS += "Server" ;}}// Include service pack (if any) and build number.pszOS +=", " + QString::fromWCharArray(osvi.szCSDVersion);return true; }else{ printf( "This sample does not support this version of Windows./n");return false;}}

你可能感兴趣的:(qt 获取win操作系统版本信息)