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

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s