Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions src/Task.Monitor.System/SystemInfo.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
Loading