How to get monitor model and serial number via WMI query or class

Started by Shivakumar

Kindly help me to get monitor model and serial number using WMI Command or class.
SoftPerfect Support forum - Andrew avatar image

Re: How to get monitor model and serial number via WMI query or class   21 June 2018, 17:57

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:

SoftPerfect support forum
Dear Team,

Guide me to add script and output column for display. Somehow I tried and I am getting details in codes
SoftPerfect Support forum - Andrew avatar image

Re: How to get monitor model and serial number via WMI query or class   23 June 2018, 18:03

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.
How can I concatenate the different results in a single variable when, for example, I have more than 2 monitors?
SoftPerfect Support forum - Andrew avatar image

Re: How to get monitor model and serial number via WMI query or class   09 February 2021, 10:17

The above script correctly deals with multiple monitors. In VBScript concatenation is done with the & symbol.
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
SoftPerfect Support forum - Andrew avatar image

Re: How to get monitor model and serial number via WMI query or class   10 February 2021, 11:53

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
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.
SoftPerfect Support forum - Andrew avatar image

Re: How to get monitor model and serial number via WMI query or class   10 February 2021, 13:02

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)
    If objMonitor.SerialNumberID(I) <> 0 Then
      SerialNo = SerialNo & Chr(objMonitor.SerialNumberID(I))
    End If
  Next
  'Concat serial numbers
  SerialNo = SerialNo & ","
Next
MsgBox SerialNo
Thanks! That works!!

Sometimes you can find a solution faster if you try the forum search, have a look at the knowledge base, or check the software user manual to see if your question has already been answered.

Our forum rules are simple:

  • Be polite.
  • Do not spam.
  • Write in English. If possible, check your spelling and grammar.

Author:

Subject

A brief and informative title for your message, approximately 4–8 words:

     

Spam prevention: please enter the following code in the input field below.

 **    **  ********  **    **  **         ******** 
 **   **   **        **   **   **    **   **       
 **  **    **        **  **    **    **   **       
 *****     ******    *****     **    **   ******   
 **  **    **        **  **    *********  **       
 **   **   **        **   **         **   **       
 **    **  ********  **    **        **   **       

Message: