#pragma comment(lib, "Version.lib" )
std::wstring GetOsVersion()
{
wchar_t path[200] = L"C:\\Windows\\System32\\kernel32.dll";
DWORD dwDummy;
DWORD dwFVISize = GetFileVersionInfoSize(path, &dwDummy);
LPBYTE lpVersionInfo = new BYTE[dwFVISize];
if (GetFileVersionInfo(path, 0, dwFVISize, lpVersionInfo) == 0)
{
return FALSE;
}
UINT uLen;
VS_FIXEDFILEINFO* lpFfi;
BOOL bVer = VerQueryValue(lpVersionInfo, L"\\", (LPVOID*)&lpFfi, &uLen);
if (!bVer || uLen == 0)
{
return FALSE;
}
DWORD dwProductVersionMS = lpFfi->dwProductVersionMS;
if (HIWORD(dwProductVersionMS) == 10 && LOWORD(dwProductVersionMS) == 0)
{
return L"Windows 10";
}
else if (HIWORD(dwProductVersionMS) == 6 && LOWORD(dwProductVersionMS) == 3)
{
return L"Windows 8.1";
}
else if (HIWORD(dwProductVersionMS) == 6 && LOWORD(dwProductVersionMS) == 2)
{
return L"Windows 8\n";
}
else if (HIWORD(dwProductVersionMS) == 6 && LOWORD(dwProductVersionMS) == 1)
{
return L"Windows 7 or Windows Server 2008 R2";
}
else if (HIWORD(dwProductVersionMS) == 6 && LOWORD(dwProductVersionMS) == 0)
{
return L"Windows Vista or Windows Server 2008";
}
else if (HIWORD(dwProductVersionMS) == 5 && LOWORD(dwProductVersionMS) == 2)
{
return L"Windows Server 2003";
}
else if (HIWORD(dwProductVersionMS) == 5 && LOWORD(dwProductVersionMS) == 1)
{
return L"Windows Server XP";
}
else if (HIWORD(dwProductVersionMS) == 5 && LOWORD(dwProductVersionMS) == 0)
{
return L"Windwos 2000";
}
return L"UNKNOWN";
}