question

Starter0815 avatar image
0 Votes"
Starter0815 asked Viorel-1 edited

Read my desktop Monitor serial Number

Hello,

via the powershell command:

 get-wmiobject wmimonitorid -namespace root\wmi|foreach-object{($_.SerialnumberID|foreach-object{[char]$_}) -join „“}

is it possible to read all serial numbers of my two connected monitors.

Is there a way to do this via VBA? Preferably so that I can output the 2 serial numbers in two different cells? A simple example script would help me a lot?

Thanks

office-vba-devoffice-scripts-excel-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered Viorel-1 edited

Check an example:

 Dim locator
 Set locator = CreateObject("WbemScripting.SWbemLocator")
    
 Dim service
 Set service = locator.ConnectServer(".", "root\wmi")
    
 Dim results
 Set results = service.ExecQuery("SELECT * FROM WmiMonitorId")
    
 Dim monitor
 For Each monitor In results
     Dim sn As String
     sn = ""
     For Each c In monitor.SerialNumberID
         sn = sn & Chr(c)
     Next
     MsgBox "Serial Number: " & sn
 Next

If it works, then replace the MsgBox line with cell operations.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.