windows系统的版本信息从OSVERSIONINFO 结构体获取,该结构体的详细定义如下:</span>
<pre name="code" class="cpp">typedef struct _OSVERSIONINFOA {
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;//主版本号
DWORD dwMinorVersion;//次版本号
DWORD dwBuildNumber;
DWORD dwPlatformId;
CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
} OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
void GetSystemName(std::string &strOsName)
{
SYSTEM_INFO info;
GetSystemInfo(&info);
OSVERSIONINFOEX os;
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
strOsName = _T("unknown OperatingSystem.");
if(GetVersionEx((OSVERSIONINFO *)&os))
{
switch(os.dwMajorVersion)
{
case 4:
switch(os.dwMinorVersion)
{
case 0:
if(os.dwPlatformId == VER_PLATFORM_WIN32_NT)
strOsName =_T("Windows NT 4.0");
else if(os.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
strOsName =_T("Windows 95");
break;
case 10:
strOsName =_T("Windows 98");
break;
case 90:
strOsName =_T("Windows Me");
break;
}
break;
case 5:
switch(os.dwMinorVersion)
{
case 0:
strOsName =_T("Windows 2000");
break;
case 1:
strOsName =_T("Windows XP");
break;
case 2:
if(os.wProductType==VER_NT_WORKSTATION
&& info.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
{
strOsName =_T("Windows XP Professional x64 Edition");
}
else if(GetSystemMetrics(SM_SERVERR2)==0)
strOsName =_T("Windows Server 2003");
else if(GetSystemMetrics(SM_SERVERR2)!=0)
strOsName =_T("Windows Server 2003 R2");
break;
}
break;
case 6:
switch(os.dwMinorVersion)
{
case 0:
if(os.wProductType == VER_NT_WORKSTATION)
strOsName =_T("Windows Vista");
else
strOsName =_T("Windows Server 2008");
break;
case 1:
if(os.wProductType == VER_NT_WORKSTATION)
strOsName =_T("Windows 7");
else
strOsName =_T("Windows Server 2008 R2");
break;
case 2:
if(os.wProductType == VER_NT_WORKSTATION)
strOsName =_T("Windows 8");
else
strOsName =_T("Windows Server 2012");
break;
case 3:
if(os.wProductType == VER_NT_WORKSTATION)
strOsName =_T("Windows 8.1");
else
strOsName =_T("Windows Server 2012 R2");
break;
}
break;
}
}
}