如何找到有效(使用中)图形卡? C#

时间:2016-05-30 11:06:01

标签: c# wmi nvidia system.diagnostics

我使用此代码查找图形卡:

        ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\cimv2");
        ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_VideoController");
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
        ManagementObjectCollection queryCollection = searcher.Get();
        string graphicsCard = "";
        foreach (ManagementObject mo in queryCollection)
        {
            foreach (PropertyData property in mo.Properties)
            {
                if (property.Name == "Description")
                {
                    graphicsCard += property.Value.ToString() + " ";
                }
            }
        }

我有两张图片卡:

My Graphic Cards

以上代码返回所有图形卡。

如何找到由windows选择的有效图形卡?

1 个答案:

答案 0 :(得分:3)

试试这个

ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController");
string graphicsCard = string.Empty;
foreach (ManagementObject obj in searcher.Get())
{
      if (obj["CurrentBitsPerPixel"] != null && obj["CurrentHorizontalResolution"] != null)
      {
            graphicsCard = obj["Name"].ToString();
      }
}