//打印出系统版本信息 void PrintOSVersionInfo() { //系统版本系统结构体:OSVERSIONINFO OSVERSIONINFO osvi; //将其内容置为0,并设置其大小 ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //调用该函数获取系统版本信息 GetVersionEx(&osvi); _tprintf(TEXT("dwBuildNumber: %d\n"),osvi.dwBuildNumber); _tprintf(TEXT("MajorVersion: %d\n"),osvi.dwMajorVersion); _tprintf(TEXT("dwMinorVersion: %d\n"),osvi.dwMinorVersion); _tprintf(TEXT("dwPlatformId: %d\n"),osvi.dwPlatformId); _tprintf(TEXT("szCSDVersion: %d\n"),osvi.szCSDVersion); } //验证系统是否是Vista void VerifyOSVersionIsVista() { //在osver变量中设置vista对应的版本信息。 OSVERSIONINFOEX osver; osver.dwOSVersionInfoSize = sizeof(osver); osver.dwMajorVersion = 6; osver.dwMinorVersion = 0; //验证vista时该值设置为0,验证win7时该值设置为1 osver.dwPlatformId = VER_PLATFORM_WIN32_NT; // Prepare the condition mask. DWORDLONG dwlConditionMask = 0;// You MUST initialize this to 0. //通过VER_SET_CONDITION宏设置要验证的信息掩码 VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_EQUAL); VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_EQUAL); VER_SET_CONDITION(dwlConditionMask, VER_PLATFORMID, VER_EQUAL); //调用VerifyVersionInfo函数进行验证。 if (VerifyVersionInfo(&osver, VER_MAJORVERSION | VER_MINORVERSION | VER_PLATFORMID, dwlConditionMask)) { // The host system is Windows Vista exactly. _tprintf(TEXT("It is Vista\n")); } else { // The host system is NOT Windows Vista. _tprintf(TEXT("It is not Vista\n")); } } void main() { PrintOSVersionInfo(); getchar(); VerifyOSVersionIsVista(); getchar(); }