修改後文章移至這裏
修改後的版本:
#define VER_SUITE_WH_SERVER 0x00008000
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
BOOL GetOSDisplayString( CString &strOSDosplay )
{
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 )
{
strOSDosplay = TEXT("Microsoft ");
// Test for the specific product.
if ( osvi.dwMajorVersion == 6 )
{
if( osvi.dwMinorVersion == 0 )
{
if( osvi.wProductType == VER_NT_WORKSTATION )
strOSDosplay += TEXT("Windows Vista ");
else strOSDosplay += TEXT("Windows Server 2008 " );
}
if ( osvi.dwMinorVersion == 1 )
{
if( osvi.wProductType == VER_NT_WORKSTATION )
strOSDosplay += TEXT("Windows 7 ");
else strOSDosplay += TEXT("Windows Server 2008 R2 " );
}
pGPI = (PGPI) GetProcAddress(
GetModuleHandle(TEXT("kernel32.dll")),
"GetProductInfo");
pGPI( osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);
switch( dwType )
{
case PRODUCT_ULTIMATE:
strOSDosplay += TEXT("Ultimate Edition" );
break;
case PRODUCT_HOME_PREMIUM:
strOSDosplay += TEXT("Home Premium Edition" );
break;
case PRODUCT_HOME_BASIC:
strOSDosplay += TEXT("Home Basic Edition" );
break;
case PRODUCT_ENTERPRISE:
strOSDosplay += TEXT("Enterprise Edition" );
break;
case PRODUCT_BUSINESS:
strOSDosplay += TEXT("Business Edition" );
break;
case PRODUCT_STARTER:
strOSDosplay += TEXT("Starter Edition" );
break;
case PRODUCT_CLUSTER_SERVER:
strOSDosplay += TEXT("Cluster Server Edition" );
break;
case PRODUCT_DATACENTER_SERVER:
strOSDosplay += TEXT("Datacenter Edition" );
break;
case PRODUCT_DATACENTER_SERVER_CORE:
strOSDosplay += TEXT("Datacenter Edition (core installation)" );
break;
case PRODUCT_ENTERPRISE_SERVER:
strOSDosplay += TEXT("Enterprise Edition" );
break;
case PRODUCT_ENTERPRISE_SERVER_CORE:
strOSDosplay += TEXT("Enterprise Edition (core installation)" );
break;
case PRODUCT_ENTERPRISE_SERVER_IA64:
strOSDosplay += TEXT("Enterprise Edition for Itanium-based Systems" );
break;
case PRODUCT_SMALLBUSINESS_SERVER:
strOSDosplay += TEXT("Small Business Server" );
break;
case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
strOSDosplay += TEXT("Small Business Server Premium Edition" );
break;
case PRODUCT_STANDARD_SERVER:
strOSDosplay += TEXT("Standard Edition" );
break;
case PRODUCT_STANDARD_SERVER_CORE:
strOSDosplay += TEXT("Standard Edition (core installation)" );
break;
case PRODUCT_WEB_SERVER:
strOSDosplay += TEXT("Web Server Edition" );
break;
}
}
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
{
if( GetSystemMetrics(SM_SERVERR2) )
strOSDosplay += TEXT( "Windows Server 2003 R2, ");
else if ( osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER )
strOSDosplay += TEXT( "Windows Storage Server 2003");
else if ( osvi.wSuiteMask==VER_SUITE_WH_SERVER )
strOSDosplay += TEXT( "Windows Home Server");
else if( osvi.wProductType == VER_NT_WORKSTATION &&
si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
{
strOSDosplay += TEXT( "Windows XP Professional x64 Edition");
}
else strOSDosplay += 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 )
strOSDosplay += TEXT( "Datacenter Edition for Itanium-based Systems" );
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
strOSDosplay += TEXT( "Enterprise Edition for Itanium-based Systems" );
}
else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
{
if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
strOSDosplay += TEXT( "Datacenter x64 Edition" );
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
strOSDosplay += TEXT( "Enterprise x64 Edition" );
else strOSDosplay += TEXT( "Standard x64 Edition" );
}
else
{
if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )
strOSDosplay += TEXT( "Compute Cluster Edition" );
else if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
strOSDosplay += TEXT( "Datacenter Edition" );
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
strOSDosplay += TEXT( "Enterprise Edition" );
else if ( osvi.wSuiteMask & VER_SUITE_BLADE )
strOSDosplay += TEXT( "Web Edition" );
else strOSDosplay += TEXT( "Standard Edition" );
}
}
}
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
{
strOSDosplay += TEXT("Windows XP ");
if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
strOSDosplay += TEXT( "Home Edition" );
else strOSDosplay += TEXT( "Professional" );
}
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
{
strOSDosplay += TEXT("Windows 2000 ");
if ( osvi.wProductType == VER_NT_WORKSTATION )
{
strOSDosplay += TEXT( "Professional" );
}
else
{
if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
strOSDosplay += TEXT( "Datacenter Server" );
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
strOSDosplay += TEXT( "Advanced Server" );
else strOSDosplay += TEXT( "Server" );
}
}
// Include service pack (if any) and build number.
if( _tcslen(osvi.szCSDVersion) > 0 )
{
strOSDosplay += TEXT(" ") ;
strOSDosplay += osvi.szCSDVersion;
}
CString strTemp;
strTemp.Format(_T("(build %d)"), osvi.dwBuildNumber);
strOSDosplay += strTemp;
if ( osvi.dwMajorVersion >= 6 )
{
if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
strOSDosplay += TEXT( ", 64-bit" );
else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL )
strOSDosplay += TEXT(", 32-bit");
}
return TRUE;
}
else
{
printf( "This sample does not support this version of Windows.\n");
return FALSE;
}
}
文章來源:http://blog.sina.com.cn/s/blog_8a7012cf010189tn.html
函數:BOOL CSystemOperate::GetOSDisplayString( LPTSTR pszOS );