Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get PC's Monitor Information Using .NET / WMI

Tags:

c#

.net

monitor

wmi

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.

like image 721
mint Avatar asked Aug 13 '10 13:08

mint


People also ask

How do I find my WMIC monitor serial number?

Type cmd in the Windows search bar at the bottom-left of the screen, then select Command Prompt from the list of results. In the Command Prompt window, type wmic bios get serialnumber and press Enter. The Service Tag (Serial Number) appears as shown in the image below.

How do I find my monitor serial number?

The serial number can usually be found on the back or bottom of your product and is either 10 or 12 digits long. The serial number can also be found on the original box of the unit.


3 Answers

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.

like image 65
Roooss Avatar answered Dec 14 '22 03:12

Roooss


You may want to try this

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

Cheers

like image 23
Iain Avatar answered Dec 14 '22 03:12

Iain


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();
             // ...
          }
       }
    }
like image 24
SwDevMan81 Avatar answered Dec 14 '22 04:12

SwDevMan81