How to get monitor model and serial number via WMI
12 posts · Closed
Kindly help me to get monitor model and serial number using WMI command or class.
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:

Dear Team,
Guide me to add script and output column for display. Somehow I tried and I am getting details in codes
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?
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 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.
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 Thanks! That works!!
Use: strComputer = Environ$("computername") instead of "." to automatically obtain computername.