For MFC code, it's a little easier:
afxGlobalData.bIsWindows7
This variable will be set to true on Windows 7 and newer.
Consider using VerifyVersionInfo()
to do requirements checking.
[^]
Here is a sample pulled from MSDN:
#include <windows.h>
#include <stdio.h>
BOOL Is_WinXP_SP2_or_Later ()
{
OSVERSIONINFOEX osvi;
DWORDLONG dwlConditionMask = 0;
int op=VER_GREATER_EQUAL;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
osvi.dwMajorVersion = 5;
osvi.dwMinorVersion = 1;
osvi.wServicePackMajor = 2;
osvi.wServicePackMinor = 0;
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 );
return VerifyVersionInfo(
&osvi,
VER_MAJORVERSION | VER_MINORVERSION |
VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
dwlConditionMask);
}
void main()
{
if(Is_WinXP_SP2_or_Later())
printf("The system meets the requirements.\n");
else printf("The system does not meet the requirements.\n");
}
VerifyVersionInfo()
Charles Oppermann is a 25-year veteran of software design. He is the original author of JAWS, the popular screen reader for people with visual impairments, and spent over a decade at Microsoft working on accessibility and user experience in the Windows, Internet Explorer and speech product groups.
Charles was a founding representative to the W3C and Web Accessibility Initiative (WAI), and the author of two technical books published by Microsoft Press. He has also worked at Cisco Systems, Amazon.com, and is currently direct test automation efforts at Malwarebytes.