How to get monitor model and serial number via WMI

12 posts · Closed

Shivakumar Guest
21 Jun 2018

Kindly help me to get monitor model and serial number using WMI command or class.

Andrew SoftPerfect
21 Jun 2018

You could use the following queries in the root\WMI namespace:

SELECT UserFriendlyName FROM WmiMonitorID
SELECT SerialNumberID FROM WmiMonitorID

However those are byte arrays and will be displayed as [XX, XX, XX, XX, ...].

For human-readable format use the following VB script under Options - Remote Scripting. It will extract the byte arrays for model name and serial number and convert them to ASCII strings:

'Input parameters
strComputer = Input.Current

'Get monitors with WMI
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\WMI")
Set colMonitors = objWMIService. _
  ExecQuery("SELECT * FROM WmiMonitorID")
For Each objMonitor in colMonitors
  'Convert serial number to ASCII
  SerialNo = ""
  For I = 0 To Ubound(objMonitor.SerialNumberID)
    SerialNo = SerialNo & Chr(objMonitor.SerialNumberID(I))
  Next
  'Convert model name to ASCII
  ProductId = ""
  For I = 0 To Ubound(objMonitor.UserFriendlyName)
    ProductId = ProductId & Chr(objMonitor.UserFriendlyName(I))
  Next
  Output.Write ProductId & " " & SerialNo
Next

Output example:

Shivakumar Totad Guest
23 Jun 2018

Dear Team,

Guide me to add script and output column for display. Somehow I tried and I am getting details in codes

Andrew SoftPerfect
23 Jun 2018

Choose Options - Remote Scripting - New and copy and paste the above script.

Give the new entry a name and make sure it's ticked in the list of scripts.

After that, there will be a new column with that name, with the script output.

Juan Olarte Guest
8 Feb 2021

How can I concatenate the different results in a single variable when, for example, I have more than 2 monitors?

Andrew SoftPerfect
8 Feb 2021

The above script correctly deals with multiple monitors. In VBScript concatenation is done with the & symbol.

Juan Olarte Guest
9 Feb 2021

I have not been able to. Could you help me by modifying the code? In my case there will always be two monitors so that the serial values ​​are stored in a single variable. I don't handle much the code in VBA, please help me. Currently I have 2 monitors, for each of them it gives me an independent MsgBox, I need to get a single MsgBox with the two values.

strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\WMI")
Set colMonitors = objWMIService. _
  ExecQuery("SELECT * FROM WmiMonitorID")
For Each objMonitor in colMonitors
  'Convert serial number to ASCII
  SerialNo = ""
  For I = 0 To Ubound(objMonitor.SerialNumberID)
    SerialNo = SerialNo & Chr(objMonitor.SerialNumberID(I))
  Next
  'Convert model name to ASCII
  ProductId = ""
  For I = 0 To Ubound(objMonitor.UserFriendlyName)
    ProductId = ProductId & Chr(objMonitor.UserFriendlyName(I))
  Next
  MSGBOX  SerialNo
Next
Andrew SoftPerfect
10 Feb 2021

Use concatenation like I suggested above and move MsgBox out of the loop:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\WMI")
Set colMonitors = objWMIService. _
  ExecQuery("SELECT * FROM WmiMonitorID")
SerialNo = ""
For Each objMonitor in colMonitors
  'Convert serial number to ASCII
  For I = 0 To Ubound(objMonitor.SerialNumberID)
    SerialNo = SerialNo & Chr(objMonitor.SerialNumberID(I))
  Next
  'Concat serial numbers
  SerialNo = SerialNo & ","
Next
MsgBox SerialNo
Juan Olarte Guest
10 Feb 2021

But this way it only shows the value once. When I have two connected monitors, it shows two msgbox. In this way it is only showing one.

Andrew SoftPerfect
10 Feb 2021

It is probably because one of your serial numbers has a terminating zero in it, which screws up the string. Add this line:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\WMI")
Set colMonitors = objWMIService. _
  ExecQuery("SELECT * FROM WmiMonitorID")
SerialNo = ""
For Each objMonitor in colMonitors
  'Convert serial number to ASCII
  For I = 0 To Ubound(objMonitor.SerialNumberID)
    [b]If objMonitor.SerialNumberID(I) <> 0 Then[/b]
      SerialNo = SerialNo & Chr(objMonitor.SerialNumberID(I))
    [b]End If[/b]
  Next
  'Concat serial numbers
  SerialNo = SerialNo & ","
Next
MsgBox SerialNo
Juan Olarte Guest
10 Feb 2021

Thanks! That works!!

Hendrik Guest
26 Jul 2022

Use: strComputer = Environ$("computername") instead of "." to automatically obtain computername.

This topic is closed. It has had no new posts for over a year, so the software versions it talks about may be out of date. Start a new topic in Network Scanner if you have a similar question.