86 lines
2.6 KiB
C#
86 lines
2.6 KiB
C#
using Microsoft.Win32;
|
|
using System;
|
|
|
|
namespace QoSManager.Services
|
|
{
|
|
public class WindowsVersionService
|
|
{
|
|
public enum WindowsEdition
|
|
{
|
|
Home,
|
|
Pro,
|
|
Enterprise,
|
|
Education,
|
|
Unknown
|
|
}
|
|
|
|
public class WindowsInfo
|
|
{
|
|
public WindowsEdition Edition { get; set; }
|
|
public string ProductName { get; set; }
|
|
public bool IsQoSSupported { get; set; }
|
|
public string VersionString { get; set; }
|
|
}
|
|
|
|
public WindowsInfo GetWindowsInfo()
|
|
{
|
|
var info = new WindowsInfo();
|
|
|
|
try
|
|
{
|
|
// Получаем информацию о версии Windows из реестра
|
|
using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"))
|
|
{
|
|
if (key != null)
|
|
{
|
|
var productName = key.GetValue("ProductName")?.ToString() ?? "Unknown";
|
|
info.ProductName = productName;
|
|
info.Edition = ParseEdition(productName);
|
|
info.IsQoSSupported = IsQoSSupported(info.Edition);
|
|
info.VersionString = $"{productName} ({info.Edition})";
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
info.ProductName = "Error reading version";
|
|
info.Edition = WindowsEdition.Unknown;
|
|
info.IsQoSSupported = false;
|
|
info.VersionString = $"Error: {ex.Message}";
|
|
}
|
|
|
|
return info;
|
|
}
|
|
|
|
private WindowsEdition ParseEdition(string productName)
|
|
{
|
|
if (string.IsNullOrEmpty(productName))
|
|
return WindowsEdition.Unknown;
|
|
|
|
productName = productName.ToLowerInvariant();
|
|
|
|
if (productName.Contains("home"))
|
|
return WindowsEdition.Home;
|
|
if (productName.Contains("pro"))
|
|
return WindowsEdition.Pro;
|
|
if (productName.Contains("enterprise"))
|
|
return WindowsEdition.Enterprise;
|
|
if (productName.Contains("education"))
|
|
return WindowsEdition.Education;
|
|
|
|
return WindowsEdition.Unknown;
|
|
}
|
|
|
|
private bool IsQoSSupported(WindowsEdition edition)
|
|
{
|
|
return edition switch
|
|
{
|
|
WindowsEdition.Pro => true,
|
|
WindowsEdition.Enterprise => true,
|
|
WindowsEdition.Education => true,
|
|
_ => false
|
|
};
|
|
}
|
|
}
|
|
}
|