Get PC's Monitor Information Using .NET / WMI

mint picture mint · Aug 13, 2010 · Viewed 22k times · Source

Is there anyway using WMI/.Net to grab monitor information such as Manufacturer, Serial Number, Monitor Size etc.?

Using a script is an option as well, or can I query the registry directly to get this information?

SELECT * FROM Win32_DesktopMonitor doesn't really return any useful information for me in this case.

Answer

Roooss picture Roooss · Aug 16, 2010

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.