AceInfinity
Emeritus, Contributor
WOW, I had not yet tested this until now. Microsoft hinted at the use of versioning functions to test build numbers... This methodology however in the Windows 10 preview would indicate that Windows 10 is actually Windows 8 however...
OS version 6.2 evaluates to true from my test code.
Without the use of the version helper API provided by Microsoft for the depreciation of other functions, this was a way to determine the exact version of an OS to an accuracy of major and minor version as far as my code is concerned. Unless this will change in the future, I don't see there any other way to detect Windows 10, other than to get file information from kernel32.dll... In which case I can get the major, minor, and build version accurately.
So I guess the question begs, does this mark the beginning of 2 more depreciated functions? (VerSetConditionMask & VerifyVersionInfo). Or is this something to be fixed later with the official release of Windows 10. Perhaps it's too early to tell, but right now this is pretty quirky.
Code:
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <iostream>
enum OS_VER_INFO { OS_VER_MAJOR, OS_VER_MINOR, OS_VER_BUILD };
BOOL os_version_equals(DWORD version, OS_VER_INFO osver_info)
{
OSVERSIONINFOEX osver_ex;
::ZeroMemory(&osver_ex, sizeof(osver_ex));
osver_ex.dwOSVersionInfoSize = sizeof(osver_ex);
DWORD type_mask;
if (osver_info == OS_VER_MAJOR)
{
osver_ex.dwMajorVersion = version;
type_mask = VER_MAJORVERSION;
}
else if (osver_info == OS_VER_MINOR)
{
osver_ex.dwMinorVersion = version;
type_mask = VER_MINORVERSION;
}
else
{
osver_ex.dwBuildNumber = version;
type_mask = VER_BUILDNUMBER;
}
ULONGLONG condition_mask = ::VerSetConditionMask(0, type_mask, VER_EQUAL);
return ::VerifyVersionInfo(&osver_ex, type_mask, condition_mask);
}
BOOL Check()
{
return os_version_equals(6, OS_VER_MAJOR) && os_version_equals(2, OS_VER_MINOR);
}
int main()
{
bool b = Check();
std::cout << std::boolalpha << b << '\n';
}
OS version 6.2 evaluates to true from my test code.
Without the use of the version helper API provided by Microsoft for the depreciation of other functions, this was a way to determine the exact version of an OS to an accuracy of major and minor version as far as my code is concerned. Unless this will change in the future, I don't see there any other way to detect Windows 10, other than to get file information from kernel32.dll... In which case I can get the major, minor, and build version accurately.
So I guess the question begs, does this mark the beginning of 2 more depreciated functions? (VerSetConditionMask & VerifyVersionInfo). Or is this something to be fixed later with the official release of Windows 10. Perhaps it's too early to tell, but right now this is pretty quirky.