From 3abbd64ff9a1f6c59af2f205a86378406b5eb352 Mon Sep 17 00:00:00 2001 From: jchas2 Date: Sat, 8 Aug 2026 10:32:17 +1000 Subject: [PATCH] Win marketing name. Closes #45 --- src/Task.Monitor.System/SystemInfo.Windows.cs | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/Task.Monitor.System/SystemInfo.Windows.cs b/src/Task.Monitor.System/SystemInfo.Windows.cs index 9ee6dcc..090bd6f 100644 --- a/src/Task.Monitor.System/SystemInfo.Windows.cs +++ b/src/Task.Monitor.System/SystemInfo.Windows.cs @@ -109,8 +109,6 @@ private static bool GetGpuCoresInternal(ref SystemStatistics systemStatistics) return true; } - private static string GetOsVersionInternal() => Environment.OSVersion.VersionString; - private static bool GetGpuMemoryInternalTotal(ref SystemStatistics systemStatistics) { // NVIDIA + AMD GPUs store memory info in the display adapter key. @@ -227,7 +225,40 @@ private static bool GetNetworkStatsInternal(ref NetworkStatistics networkStatist Pdh.PdhCloseQuery(hQuery); return true; } - + + private static string GetOsVersionInternal() + { + // Windows product/display name determination is a real mess. + const string RegPath = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion"; + const string WINDOWS_10 = "Windows 10"; + const string WINDOWS_11 = "Windows 11"; + using RegistryKey? key = Registry.LocalMachine.OpenSubKey(RegPath); + + if (key == null) { + return Environment.OSVersion.VersionString; + } + + string productName = key.GetValue("ProductName") as string ?? string.Empty; + string displayVersion = key.GetValue("DisplayVersion") as string ?? string.Empty; + string currBuildNumber = key.GetValue("CurrentBuildNumber") as string ?? string.Empty; + + if (!string.IsNullOrEmpty(productName)) { + if (int.TryParse(currBuildNumber, out int buildNumber) && buildNumber >= 22000) { + // Fix up issue where Win 10 -> Win 11 upgrade does not update ProductName in Registry. + if (productName.Contains(WINDOWS_10, StringComparison.OrdinalIgnoreCase)) { + productName = productName.Replace(WINDOWS_10, WINDOWS_11, StringComparison.OrdinalIgnoreCase); + } + } + + return string.IsNullOrWhiteSpace(displayVersion) + ? productName + : $"{productName} {displayVersion}"; + } + + // For older versions of Windows. + return Environment.OSVersion.VersionString; + } + private static unsafe bool GetSystemMemoryInternal(ref SystemStatistics systemStatistics) { systemStatistics.AvailablePageFile = 0;