基础 - 获得系统版本
Posted 生如逆旅 一苇以航
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基础 - 获得系统版本相关的知识,希望对你有一定的参考价值。
1 // 获得系统版本.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <windows.h> 6 7 #include <atlstr.h> //非MFC字符串对象 8 #include <cstringt.h>//MFC字符串对象 9 10 #include <iostream> 11 12 using namespace std; 13 14 15 16 17 int main() 18 { 19 CString strOS; 20 21 OSVERSIONINFOEX OsVerInfoEx; // 版本信息 22 OsVerInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 23 GetVersionEx((OSVERSIONINFO*)&OsVerInfoEx); // 注意转换类型 24 25 switch (OsVerInfoEx.dwPlatformId) 26 { 27 28 case VER_PLATFORM_WIN32_NT: 29 if (OsVerInfoEx.dwMajorVersion <= 4) 30 strOS = "WindowsNT"; 31 if (OsVerInfoEx.dwMajorVersion == 5 && OsVerInfoEx.dwMinorVersion == 0) 32 strOS = "Windows2000"; 33 if (OsVerInfoEx.dwMajorVersion == 5 && OsVerInfoEx.dwMinorVersion == 1) 34 strOS = "WindowsXP"; 35 if (OsVerInfoEx.dwMajorVersion == 5 && OsVerInfoEx.dwMinorVersion == 2) 36 strOS = "Windows2003"; 37 if (OsVerInfoEx.dwMajorVersion == 6 && OsVerInfoEx.dwMinorVersion == 0) 38 strOS = "WindowsVista"; 39 if (OsVerInfoEx.dwMajorVersion == 6 && OsVerInfoEx.dwMinorVersion == 1) 40 strOS = "Windows7"; 41 if (OsVerInfoEx.dwMajorVersion == 6 && OsVerInfoEx.dwMinorVersion == 2) 42 strOS = "Windows10"; 43 } 44 45 printf("%S", strOS); 46 return 0; 47 }
以上是关于基础 - 获得系统版本的主要内容,如果未能解决你的问题,请参考以下文章