通过 ManagementObjectSearcher 类,初始化root\\CIMV2,查询 Win32_VideoController,获取显示适配器信息
分别获取:
Name,AdapterRAM,CurrentHorizontalResolution,CurrentVerticalResolution,CurrentRefreshRate,MinRefreshRate,MaxRefreshRate,DriverVersion
/// <summary>
/// 获取显卡信息
/// </summary>
/// <returns></returns>
public static string GetDisplayAdapters()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_VideoController");
StringBuilder stringBuilder = new StringBuilder();
uint i = 1;
foreach (ManagementObject wmi in searcher.Get())
{
var n = wmi.GetPropertyValue("Name")?.ToString().Replace("(TM)", "™").Replace("(tm)", "™").Replace("(R)", "®").Replace("(r)", "®").Replace("(C)", "©").Replace("(c)", "©");
var ram = Convert.ToInt64(wmi.GetPropertyValue("AdapterRAM")) / 1024 / 1024 / 1024;
var chr = wmi.GetPropertyValue("CurrentHorizontalResolution");
var cvr = wmi.GetPropertyValue("CurrentVerticalResolution");
var cr = wmi.GetPropertyValue("CurrentRefreshRate");
var minR = wmi.GetPropertyValue("MinRefreshRate");
var maxR = wmi.GetPropertyValue("MaxRefreshRate");
var dv = wmi.GetPropertyValue("DriverVersion");
stringBuilder.AppendLine($"序号{i}>>{n},{ram}GB RAM,分辨率{chr}x{cvr},刷新率{cr}Hz,最大可设刷新率{maxR},最小可设刷新率{minR},驱动版本{dv}");
stringBuilder.AppendLine();
i++;
}
return stringBuilder.ToString();
}