Click here to Skip to main content
15,880,364 members
Articles / Programming Languages / Visual C++ 10.0
Alternative
Tip/Trick

Check Windows 7 version in Visual C++

Rate me:
Please Sign up or sign in to vote.
4.67/5 (3 votes)
2 Aug 2011CPOL 8.6K   2  
How to check Windows 7 version in Visual C++

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:

C++
#include <windows.h>
#include <stdio.h>

BOOL Is_WinXP_SP2_or_Later () 
{
   OSVERSIONINFOEX osvi;
   DWORDLONG dwlConditionMask = 0;
   int op=VER_GREATER_EQUAL;
 
   // Initialize the OSVERSIONINFOEX structure.

   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
   osvi.dwMajorVersion = 5;
   osvi.dwMinorVersion = 1;
   osvi.wServicePackMajor = 2;
   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);
}
 
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");
}

C++
VerifyVersionInfo()

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Program Manager
United States United States
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.

Comments and Discussions

 
-- There are no messages in this forum --