C#检测哪个显卡驱动video

我的C#应用​​程序位于具有Intel主板和图形芯片组的嵌入式盒子上。 ATI显卡已经上PCI Express。 通常显卡驱动video,但如果ATI卡出现故障,则video会从图形芯片组中传出。

我必须检测ATI显卡的故障以进行诊断。

有关如何执行此操作的任何想法/示例代码。

在此先感谢Raju

这应该有希望让你开始。

添加对System.Management的引用,然后您可以执行以下操作:

 ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DisplayConfiguration"); string graphicsCard = string.Empty; foreach (ManagementObject mo in searcher.Get()) { foreach (PropertyData property in mo.Properties) { if (property.Name == "Description") { graphicsCard = property.Value.ToString(); } } } 

就我而言, graphicsCard等于

NVIDIA GeForce 8400 GS(微软公司 – WDDM v1.1)

我并不喜欢所选答案如何仅返回第一个video控制器。 此外,没有必要循环所有属性。 得到你需要的。 如果CurrentBitsPerPixel不为null,那么您正在查看其中一个活动控制器。 我正在使用@bairog建议的Win32_VideoController,而不是弃用的Win32_DisplayConfiguration。

 ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController"); foreach (ManagementObject mo in searcher.Get()) { PropertyData currentBitsPerPixel = mo.Properties["CurrentBitsPerPixel"]; PropertyData description = mo.Properties["Description"]; if (currentBitsPerPixel != null && description != null) { if (currentBitsPerPixel.Value != null) System.Console.WriteLine(description.Value); } } 

我的机器有3个video控制器。 第一个不活跃(ShoreTel)。 第二个是活动的,但不是video卡(Desktop Authority)。 第三个是我的NVidia。 此代码将打印出DA控制器和NVidia控制器。

推荐答案仅适用于单个video卡系统。 当我有ATI和Nvidia卡时 – 即使该显示器插入Nvidia卡,WMI查询返回ATI,dxdiag显示Nvidia并且该卡上运行游戏(使用)。

我可以确定正确的video卡的唯一方法是使用SlimDX创建DX设备并检查它使用的卡。 但是.dll的重量超过3Mb。

 var graphicsCardName = new Direct3D().Adapters[0].Details.Description; 

你的问题并不完全清楚,所以我不确定这个想法是否会有所帮助。

或许非常简单就足够了:

如果两个图形卡运行不同的分辨率,请使用以下方法检查显示器

 System.Windows.Forms.SystemInformation.PrimaryMonitorSize 

同样,如果一个卡支持多个监视器,请使用SystemInformation.MonitorCount检查监视器的数量。

我尝试了这个问题的所有方法,但没有一个给我一个正确的答案。 但是我发现使用Win32_DisplayControllerConfiguration类可以获得当前的function。 虽然根据MSDN这个类已经过时 ,但它是唯一一个返回正确答案的类:

 using System; using System.Management; using System.Windows.Forms; namespace WMISample { public class MyWMIQuery { public static void Main() { try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DisplayControllerConfiguration"); foreach (ManagementObject queryObj in searcher.Get()) { Console.WriteLine("----------------------------------- "); Console.WriteLine("Win32_DisplayControllerConfiguration instance"); Console.WriteLine("-----------------------------------"); Console.WriteLine("Name: {0}", queryObj["Name"]); } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); } } } } 

(由WMI Code Creator生成的代码 ,如果你搞乱WMI,这是一个很好的工具。)

这在我的Windows 10(RS2)+英特尔(R)HD Graphics 4600 + NVIDIA GeForce GTX 1080系统上提供了GeForce GTX 1080