C# detect which graphics card drives video

前端 未结 5 671
萌比男神i
萌比男神i 2021-01-01 01:55

My C# application sits on the embedded box which has Intel motherboard and graphics chipset. ATI graphics card is put on to PCI express. Generally graphics card drives the v

5条回答
  •  青春惊慌失措
    2021-01-01 02:41

    I'm not a fan of how the selected answer only returns the first video controller. Also, there's no need to loop over all the properties. Just get the ones you need. If CurrentBitsPerPixel is not null, then you're looking at one of the active controllers. I'm using Win32_VideoController as suggested by @bairog, instead of the deprecated 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);
        }
    }
    

    My machine has 3 video controllers. The first one is not active (ShoreTel). The second one is active, but is not the video card (Desktop Authority). The third one is my NVidia. This code will print out both the DA controller and the NVidia controller.

提交回复
热议问题