#include "StdAfx.h"#include"GetSysInfo.h"#include"float.h"#include"winperf.h"GetSysInfo::GetSysInfo(void)
{
}
GetSysInfo::~GetSysInfo(void)
{
}void GetSysInfo::GetOSVersion(CString &strOSVersion,CString &strServiceVersion)
{
CString str;
OSVERSIONINFOEX osvi;
SYSTEM_INFO si;
BOOL bOsVersionInfoEx;
ZeroMemory(&si, sizeof(SYSTEM_INFO));
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize= sizeof(OSVERSIONINFOEX);if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
{
osvi.dwOSVersionInfoSize= sizeof(OSVERSIONINFO);
GetVersionEx ( (OSVERSIONINFO*) &osvi);
}
GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")),"GetNativeSystemInfo");
GetSystemInfo(&si);switch(osvi.dwPlatformId)
{caseVER_PLATFORM_WIN32_NT:if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0)
{if( osvi.wProductType ==VER_NT_WORKSTATION )
{
str.Format(_T("Windows Vista"));
}else{
str.Format(_T("Windows Server \"Longhorn\""));
}
}if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
{if( GetSystemMetrics(SM_SERVERR2) )
{
str.Format(_T("Microsoft Windows Server 2003 \"R2\""));
}else if( osvi.wProductType == VER_NT_WORKSTATION &&si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
{
str.Format(_T("Microsoft Windows XP Professional x64 Edition"));
}else{
str.Format(_T("Microsoft Windows Server 2003,"));
}
}if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
{
str.Format(_T("Microsoft Windows XP"));
}if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
str.Format(_T("Microsoft Windows 2000"));if ( osvi.dwMajorVersion <= 4)
{
str.Format(_T("Microsoft Windows NT"));
}//Test for specific product on Windows NT 4.0 SP6 and later.
if( bOsVersionInfoEx )
{//将Service Pack 版本保存
strServiceVersion.Format(_T("Service Pack %d"),osvi.wServicePackMajor);//Test for the workstation type.
if ( osvi.wProductType == VER_NT_WORKSTATION &&si.wProcessorArchitecture!=PROCESSOR_ARCHITECTURE_AMD64)
{if( osvi.dwMajorVersion == 4)
str= str + _T("Workstation 4.0");else if( osvi.wSuiteMask &VER_SUITE_PERSONAL )
str= str + _T("Home Edition");else str = str + _T( "Professional");
}//Test for the server type.
else if ( osvi.wProductType == VER_NT_SERVER ||osvi.wProductType==VER_NT_DOMAIN_CONTROLLER )
{if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==2)
{if ( si.wProcessorArchitecture ==PROCESSOR_ARCHITECTURE_IA64 )
{if( osvi.wSuiteMask &VER_SUITE_DATACENTER )
str= str + _T("Datacenter Edition for Itanium-based Systems");else if( osvi.wSuiteMask &VER_SUITE_ENTERPRISE )
str= str + _T("Enterprise Edition for Itanium-based Systems");
}else if ( si.wProcessorArchitecture ==PROCESSOR_ARCHITECTURE_AMD64 )
{if( osvi.wSuiteMask &VER_SUITE_DATACENTER )
str= str + _T( "Datacenter x64 Edition");else if( osvi.wSuiteMask &VER_SUITE_ENTERPRISE )
str= str + _T( "Enterprise x64 Edition");else str = str + _T( "Standard x64 Edition");
}else{if( osvi.wSuiteMask &VER_SUITE_DATACENTER )
str= str + _T( "Datacenter Edition");else if( osvi.wSuiteMask &VER_SUITE_ENTERPRISE )
str= str + _T( "Enterprise Edition");else if ( osvi.wSuiteMask &