要获取C#中的显卡信息,你可以使用管理对象提供的WMI(Windows Management Instrumentation)类。
下面是实现代码示例:
using System.Management;
public static void GetGraphicsCardInformation()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController");
foreach (ManagementObject obj in searcher.Get())
{
Console.WriteLine("Name - " + obj["Name"].ToString());
Console.WriteLine("Adapter Compatibility - " + obj["AdapterCompatibility"].ToString());
Console.WriteLine("Adapter RAM - " + obj["AdapterRAM"].ToString());
Console.WriteLine("Driver Version - " + obj["DriverVersion"].ToString());
Console.WriteLine("Video Processor - " + obj["VideoProcessor"].ToString());
}
}
此代码使用WMI查询了所有Win32_VideoController对象,通过迭代遍历每个对象并打印显卡的名称,适配器兼容性,适配器RAM,驱动程序版本和视频处理器信息。