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;