Search code examples
c#wminvidiasystem.diagnostics

How to find Active (In Use) Graphic Cards?


I used this code for finding graphic cards:

        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() + " ";
                }
            }
        }

I have two graphic cards:

My Graphic Cards

Above code return all graphic cards.

How to find active graphic card that chosen by windows?


Solution

  • try this

    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();
          }
    }