下面的函数判断系统是否是vista之后,返回true/false
如果需要改为判断xp或者win7前后的系统,只需要修改dwMajorVersion即可,具体不同系统对应的版本信息可以查阅微软官方文档,在这里.
bool IsVistaOrLater() { OSVERSIONINFOEX osvi; DWORDLONG dwlConditionMask = 0; int op=VER_GREATER_EQUAL; // Initialize the OSVERSIONINFOEX structure. ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); osvi.dwMajorVersion = 6; // 这是vista的最低版本号6.0 osvi.dwMinorVersion = 0; osvi.wServicePackMajor = 0; // 这是sp版本号0.0 osvi.wServicePackMinor = 0; // Initialize the condition mask. VER_SET_CONDITION( dwlConditionMask, VER_MAJORVERSION, op ); VER_SET_CONDITION( dwlConditionMask, VER_MINORVERSION, op ); VER_SET_CONDITION( dwlConditionMask, VER_SERVICEPACKMAJOR, op ); VER_SET_CONDITION( dwlConditionMask, VER_SERVICEPACKMINOR, op ); // Perform the test. return VerifyVersionInfo( &osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, dwlConditionMask); }头文件:
#include <windows.h> #include <stdio.h>
No comments :
Post a Comment