How to check Windows version in C++

BOOL WINAPI IsWindows7()

{

 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;

 osvi.dwMinorVersion = 1; // Windows 7



 // Initialize the condition mask.

 VER_SET_CONDITION( dwlConditionMask, VER_MAJORVERSION, op );

 VER_SET_CONDITION( dwlConditionMask, VER_MINORVERSION, op );



 // Perform the test.

 return VerifyVersionInfo(&osvi,VER_MAJORVERSION | VER_MINORVERSION,dwlConditionMask);

}



BOOL WINAPI IsWindowsVista()

{

 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;



 // Initialize the condition mask.

 VER_SET_CONDITION( dwlConditionMask, VER_MAJORVERSION, op );



 // Perform the test.

 return VerifyVersionInfo(&osvi,VER_MAJORVERSION | VER_MINORVERSION,dwlConditionMask);

}





BOOL WINAPI IsWindowsXP() 

{

   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;



   // Initialize the condition mask.



   VER_SET_CONDITION( dwlConditionMask, VER_MAJORVERSION, op );

   VER_SET_CONDITION( dwlConditionMask, VER_MINORVERSION, op );



   // Perform the test.



   return VerifyVersionInfo(

      &osvi, 

      VER_MAJORVERSION | VER_MINORVERSION,

      dwlConditionMask);

}



BOOL WINAPI IsWindowsXPSP2() 

{

   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);

}

Comments

Popular posts from this blog

Quricol - QR code generator library

EIDNative Library 2.0 released

Quricol 2.0 - QR Code generator