Created
September 12, 2019 10:25
-
-
Save katahiromz/85e8d46acd44db4f3f6bcf144553720d to your computer and use it in GitHub Desktop.
DoGetOSInfo.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <string> | |
#include <strsafe.h> | |
std::wstring DoGetOSInfo(void) | |
{ | |
HKEY hKey = NULL; | |
WCHAR szText[32]; | |
DWORD dwValue, cbData; | |
std::wstring ret; | |
LONG error; | |
static const WCHAR s_szCurVer[] = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"; | |
::RegOpenKeyExW(HKEY_LOCAL_MACHINE, s_szCurVer, 0, KEY_READ, &hKey); | |
if (!hKey) | |
return FALSE; | |
// Windows 10 Home | |
cbData = sizeof(szText); | |
error = ::RegQueryValueExW(hKey, L"ProductName", NULL, NULL, (LPBYTE)szText, &cbData); | |
if (!error) | |
{ | |
ret = szText; | |
} | |
else | |
{ | |
ret = L"Unknown OS"; | |
return ret; | |
} | |
// Version 1903 | |
cbData = sizeof(szText); | |
error = ::RegQueryValueExW(hKey, L"ReleaseId", NULL, NULL, (LPBYTE)szText, &cbData); | |
if (!error) | |
{ | |
ret += L" Version "; | |
ret += szText; | |
} | |
else | |
{ | |
return ret; | |
} | |
// (OS Build 18362 | |
szText[0] = 0; | |
cbData = sizeof(szText); | |
::RegQueryValueExW(hKey, L"CurrentBuild", NULL, NULL, (LPBYTE)szText, &cbData); | |
ret += L" (OS Build "; | |
ret += szText; | |
// .295) | |
dwValue = 0; | |
cbData = sizeof(dwValue); | |
::RegQueryValueExW(hKey, L"UBR", NULL, NULL, (LPBYTE)&dwValue, &cbData); | |
StringCbPrintfW(szText, sizeof(szText), L".%u)", dwValue); | |
ret += szText; | |
::RegCloseKey(hKey); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment