C++判断系统版本

乱编乱写 4097 Views 0 Comments

很多时候我们要根据系统的不同版本进行不同的操作

下面给出了如何判断Windows操作系统的版本函数

int VRVGetSystemVersion(SYSTEM_VERSION *pnSystemVersion)
{ 
    OSVERSIONINFO osvi; 
    BOOL bOsVersionInfoEx;

   *pnSystemVersion = ENUM_SYSTEM_UNKOWN; 
    memset(&osvi, 0, sizeof(OSVERSIONINFO)); 
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

    if (!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *) &osvi)) ) 
    { 
   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 
   if (! GetVersionEx( (OSVERSIONINFO *) &osvi) ) 
   { 
  return FALSE; 
   } 
    }

    switch (osvi.dwPlatformId) 
    { 
   case VER_PLATFORM_WIN32_NT: 
  if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0) 
  { 
 *pnSystemVersion = ENUM_SYSTEM_WIN_VISTA; 
  } 
 
  if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) 
  { 
 *pnSystemVersion = ENUM_SYSTEM_WIN_SER_2003; 
  } 
 
  if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) 
  { 
 *pnSystemVersion = ENUM_SYSTEM_WIN_XP; 
  } 
 
  if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0) 
  { 
 *pnSystemVersion = ENUM_SYSTEM_WIN_2000; 
  } hackhp博客
 
  if ( osvi.dwMajorVersion <= 4) 
  { 
 *pnSystemVersion = ENUM_SYSTEM_WIN_NT; 
  } 
 
  if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1) 
  { 
 *pnSystemVersion = ENUM_SYSTEM_WIN_7; 
  } 
  break; 
   case VER_PLATFORM_WIN32_WINDOWS: 
  if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0 ) 
  { 
 *pnSystemVersion = ENUM_SYSTEM_WIN_95; 
  } 
 
  if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) 
  { 
 *pnSystemVersion = ENUM_SYSTEM_WIN_98; 
  } 
 
  if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) 
  { 
 *pnSystemVersion = ENUM_SYSTEM_WIN_ME; 
  } 
 
  break; 
   default: 
  *pnSystemVersion = ENUM_SYSTEM_UNKOWN; 
  break; 
 
    } 
    return TRUE; 
}

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
loading