当前位置: 代码迷 >> 其他开发语言 >> 获取操作系统版本时怎么区分2008 server和vista
  详细解决方案

获取操作系统版本时怎么区分2008 server和vista

热度:1873   发布时间:2013-02-26 00:00:00.0
获取操作系统版本时如何区分2008 server和vista?
通过GetVersionEx获取系统版本时,2008 server和vista的主版本号和次版本号都是6、0.这样就无法区分是2008还是vista了!请问有没有别的办法来区分这两种操作系统?
C/C++ code
CString CDialogInfo::GetSystemVersion(){    CString strVersion = "";    OSVERSIONINFOEX osvi;    ZeroMemory(&osvi,sizeof(osvi));    osvi.dwOSVersionInfoSize = sizeof(osvi);    if (!GetVersionEx((OSVERSIONINFO*)&osvi))    {        osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);        if (!GetVersionEx((OSVERSIONINFO*)&osvi))        {            return strVersion;        }    }    //判断系统类型//     char szTemp[MAX_PATH] = {0};//     sprintf(szTemp,"PlatFormID:%d MajorVersion:%d MinorVersion:%d",osvi.dwPlatformId,osvi.dwMajorVersion,osvi.dwMinorVersion);//     MessageBox(szTemp);    switch(osvi.dwPlatformId)    {    case VER_PLATFORM_WIN32_NT:        if ( osvi.dwMajorVersion <= 4 )            strVersion += "winnt";        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )            strVersion += "win2000";        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )            strVersion += "winxp";        else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)            strVersion += "win2003";        if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0)            strVersion += "vista";        break;    case VER_PLATFORM_WIN32_WINDOWS:        if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)            strVersion += "win95";        if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)            strVersion += "win98";        if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)            strVersion += "winME";         break;    case VER_PLATFORM_WIN32s:        strVersion += "win32s";         break;    }    return strVersion;}


------解决方案--------------------------------------------------------
更多的细节可以从注册表HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion下获得。

------解决方案--------------------------------------------------------
vista与2008的大小版本都是一样的6.0,要区分就要通过wProductType来识别!

if( VerInfoEx.dwMajorVersion == 6 )
{
if (VerInfoEx.wProductType == VER_NT_SERVER || VerInfoEx.wProductType == VER_NT_DOMAIN_CONTROLLER)
return WINDOWS_2008;


return WINDOWS_VISTA;
}
------解决方案--------------------------------------------------------
有道理,似乎没有API直接获得操作系统名称(至少我不知道)。

另外,请版主关注一下,在这个帖子里:http://topic.csdn.net/u/20090704/14/9813bf82-1037-4249-88aa-e57c5877ae0e
那个FireAngel在技术上辩论失败后就开始玩纯骂了,他讨论技术的同时有一些过激的言论,我是不会介意的,但是他搞纯骂,是不是应该清理一下呢。:)
  相关解决方案