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 }
时间: 2024-10-25 12:43:39