Get PC's Monitor Information Using .NET / WMI

Hey, I use this tool for a lot of my WMI work, especially when prototyping and creating POCs....

Microsoft WMI Code Generator

This tool is great for creating quick console app code for any wmi query or method invocation in both C# and VB.NET

try
        {
            ManagementObjectSearcher searcher = 
                new ManagementObjectSearcher("root\\CIMV2", 
                "SELECT * FROM Win32_DesktopMonitor"); 

            foreach (ManagementObject queryObj in searcher.Get())
            {
                Console.WriteLine("-----------------------------------");
                Console.WriteLine("Win32_DesktopMonitor instance");
                Console.WriteLine("-----------------------------------");
                Console.WriteLine("Description: {0}", queryObj["Description"]);
            }
        }
        catch (ManagementException e)
        {
            MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
        }

The code above will get you the make and model of the monitor.


You may want to try this

https://raw.githubusercontent.com/MaxAnderson95/Get-Monitor-Information/master/Get-Monitor.ps1

Cheers


That select query should give you what you want. Here is the documentation which contains the details of the query.

Then you could do something like this:

    public void GetMonitorDetails()
    {
       using(ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DesktopMonitor")
       {
          foreach(ManagementObject currentObj in searcher.Get())
          {
             String name = currentObj("Name").ToString();
             String device_id = currentObj("DeviceID").ToString();
             // ...
          }
       }
    }

Tags:

C#

.Net

Wmi

Monitor