From e85fd68d8204728c8032dee8b7443b61fc22c8aa Mon Sep 17 00:00:00 2001 From: Quantum Date: Wed, 26 Jan 2022 05:23:45 -0500 Subject: [PATCH] [host] windows: read ProductName from registry if possible For Windows 10, it so happens that the major.minor is 10.0. This is not usually a given, e.g. on Windows 7 where it would read 6.1, on Windows 8 it would read 6.2, and on Windows 8.1 it would read 6.3. This is obviously undesirable, so we should just read the ProductName from registry if possible. This results in something like: OS Name: Windows 10 Pro for Workstations (Build: 19043) --- host/platform/Windows/src/platform.c | 45 +++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/host/platform/Windows/src/platform.c b/host/platform/Windows/src/platform.c index 0a9c2c55..e40c7959 100644 --- a/host/platform/Windows/src/platform.c +++ b/host/platform/Windows/src/platform.c @@ -615,6 +615,21 @@ KVMFROS os_getKVMFRType(void) return KVMFR_OS_WINDOWS; } +static bool getProductName(char * buffer, DWORD bufferSize) +{ + LSTATUS status = RegGetValueA(HKEY_LOCAL_MACHINE, + "Software\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", + RRF_RT_REG_SZ, NULL, buffer, &bufferSize); + + if (status != ERROR_SUCCESS) + { + DEBUG_WINERROR("Failed to read ProductName from registry", status); + return false; + } + + return true; +} + const char * os_getOSName(void) { if (app.osVersion) @@ -624,14 +639,28 @@ const char * os_getOSName(void) osvi.dwOSVersionInfoSize = sizeof(osvi); GetVersionExA(&osvi); - alloc_sprintf( - &app.osVersion, - "Windows %lu.%lu (Build: %lu) %s", - osvi.dwMajorVersion, - osvi.dwMinorVersion, - osvi.dwBuildNumber, - osvi.szCSDVersion - ); + char productName[1024]; + if (getProductName(productName, sizeof(productName))) + { + alloc_sprintf( + &app.osVersion, + "%s (Build: %lu) %s", + productName, + osvi.dwBuildNumber, + osvi.szCSDVersion + ); + } + else + { + alloc_sprintf( + &app.osVersion, + "Windows %lu.%lu (Build: %lu) %s", + osvi.dwMajorVersion, + osvi.dwMinorVersion, + osvi.dwBuildNumber, + osvi.szCSDVersion + ); + } return app.osVersion; }