Monitor Serial Numbers VBS

I am looking to get the current vbs script that I found on the net to get the multiple monitor information that it finds, but use a txt file with hostnames and write the result to an xls or cvs or something. Any information on how to do this would be great. Thanks.

'based on script from, read_and_parse_monitor_edid_information.vbs
'Original Author: Michael Baird
'original comment :The script reads and parses the monitor EDID information from the registry in order to retrieve 

asset information.

'Modifications by Alan Kaplan --
'improved error handling, permit query of remote WMI, display changes
'8/30 elimated duplicates in array, added echoandlog routine
'Note that all the interesting coding is Baird's work.  

' Monitor EDID Information'
'17 June 2004
'coded by Michael Baird
'and released under the terms of GNU open source license agreement
'(that is of course If you CAN release code that uses WMI under GNU)
'Please give me credit If you use my code

'this code is based on the EEDID spec found at
'and by my hacking around in the windows registry
'the code was tested on WINXP,WIN2K and WIN2K3
'it should work on WINME and WIN98SE
'It should work with multiple monitors, but that hasn't been tested either.
'It should be noted that this is not 100% reliable
'I have witnessed occasions where for one reason or another windows
'can't or doesn't read the EDID info at boot (example would be someone
'booting with the monitor turned off) and so windows changes the active
'monitor to "Default_Monitor"
'Another reason for reliability problems is that there is no
'requirement in the EDID spec that a manufacture include the
'serial number in the EDID data AND only EDIDv1.2 and beyond 
'have a requirement that the EDID contain a descriptive
'model name
'That being said, here goes....
'Monitors are stored in HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\
'Unfortunately, not only monitors are stored here Video Chipsets and maybe some other stuff
'is also here.
'Monitors in "HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" are organized like this:
'     HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\<VESA_Monitor_ID>\<PNP_ID>\
'Since not only monitors will be found under DISPLAY sub key you need to find out which
'devices are monitors.
'This can be deterimined by looking at the value "HardwareID" located
'at HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\<VESA_Monitor_ID\<PNP_ID>\
'If the device is a monitor then the "HardwareID" value will contain the data "Monitor\<VESA_Monitor_ID>"
'The Next difficulty is that all monitors are stored here not just the one curently plugged in.
'So, If you ever switched monitors the old one(s) will still be in the registry.
'You can tell which monitor(s) are active because they will have a sub-key named "Control"
Option Explicit
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim strComputer, message

Dim intMonitorCount
Dim oRegistry, sBaseKey, sBaseKey2, sBaseKey3, skey, skey2, skey3
Dim sValue
dim i, iRC, iRC2, iRC3
Dim arSubKeys, arSubKeys2, arSubKeys3, arrintEDID
Dim strRawEDID
Dim ByteValue, strSerFind, strMdlFind
Dim intSerFoundAt, intMdlFoundAt, findit
Dim tmp, tmpser, tmpmdl, tmpctr
Dim batch, bHeader
batch = False

If WScript.Arguments.Count = 1 Then
	strComputer = WScript.Arguments(0)
	batch = True
	strComputer = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
	strComputer = InputBox("Check Monitor info for what PC","PC Name?",strComputer)
End If 

If strcomputer = "" Then WScript.Quit
strComputer = UCase(strComputer)

If batch Then 
	Dim fso,logfile, appendout
	logfile = wshShell.ExpandEnvironmentStrings("%userprofile%") & "\desktop\MonitorInfo.csv"
	'setup Log
	Const ForAppend = 8
	Set fso = CreateObject("Scripting.FileSystemObject")
	If Not fso.FileExists(logfile) Then bHeader = True
	set appendout = fso.OpenTextFile(logfile, ForAppend, True)
	If bHeader Then 
		appendout.writeline "Computer,Model,Serial #,Vendor ID,Manufacture Date,Messages"
	End If 
End If 

Dim strarrRawEDID()
'get a handle to the WMI registry object
On Error Resume Next
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & 


If Err <> 0 Then
	If batch Then 
		EchoAndLog strComputer & ",,,,," & Err.Description
		MsgBox "Failed. " & Err.Description,vbCritical + vbOKOnly,strComputer
	End If 
End If 

sBaseKey = "SYSTEM\CurrentControlSet\Enum\DISPLAY\"
'enumerate all the keys HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\
iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys)
For Each sKey In arSubKeys
     'we are now in the registry at the level of:
     'we need to dive in one more level and check the data of the "HardwareID" value
	sBaseKey2 = sBaseKey & sKey & "\"
	iRC2 = oRegistry.EnumKey(HKLM, sBaseKey2, arSubKeys2)
	For Each sKey2 In arSubKeys2
          'now we are at the level of:
          'so we can check the "HardwareID" value
		oRegistry.GetMultiStringValue HKLM, sBaseKey2 & sKey2 & "\", "HardwareID", sValue
		for tmpctr=0 to ubound(svalue)
			If lcase(left(svalue(tmpctr),8))="monitor\" then
                    'If it is a monitor we will check for the existance of a control subkey
                    'that way we know it is an active monitor
                    sBaseKey3 = sBaseKey2 & sKey2 & "\"
                    iRC3 = oRegistry.EnumKey(HKLM, sBaseKey3, arSubKeys3)
                    For Each sKey3 In arSubKeys3
                    'Kaplan edit
                    strRawEDID = ""
                         If skey3="Control" Then
                              'If the Control sub-key exists then we should read the edid info
                              oRegistry.GetBinaryValue HKLM, sbasekey3 & "Device Parameters\", "EDID", arrintEDID
			               If vartype(arrintedid) <> 8204 then 'and If we don't find it...
                                   strRawEDID="EDID Not Available" 'store an "unavailable message
                                   for each bytevalue in arrintedid 'otherwise conver the byte array from the 

registry into a string (for easier processing later)
                                        strRawEDID=strRawEDID & chr(bytevalue)
                              End If
                              'now take the string and store it in an array, that way we can support multiple 

                              redim preserve strarrRawEDID(intMonitorCount)
                          End If
			End If
'now the EDID info for each active monitor is stored in an array of strings called strarrRawEDID
'so we can process it to get the good stuff out of it which we will store in a 5 dimensional array
'called arrMonitorInfo, the dimensions are as follows:
'0=VESA Mfg ID, 1=VESA Device ID, 2=MFG Date (M/YYYY),3=Serial Num (If available),4=Model Descriptor
'5=EDID Version
On Error Resume Next 
dim arrMonitorInfo()
redim arrMonitorInfo(intMonitorCount-1,5)
dim location(3)
for tmpctr=0 to intMonitorCount-1
     If strarrRawEDID(tmpctr) <> "EDID Not Available" then
          'first get the model and serial numbers from the vesa descriptor
          'blocks in the edid.  the model number is required to be present
          'according to the spec. (v1.2 and beyond)but serial number is not
          'required.  There are 4 descriptor blocks in edid at offset locations
          '&H36 &H48 &H5a and &H6c each block is 18 bytes long
          'you can tell If the location contains a serial number If it starts with &H00 00 00 ff
          strSerFind=chr(&H00) & chr(&H00) & chr(&H00) & chr(&Hff)
          'or a model description If it starts with &H00 00 00 fc
          strMdlFind=chr(&H00) & chr(&H00) & chr(&H00) & chr(&Hfc)
          for findit = 0 to 3
               If instr(location(findit),strSerFind)>0 then
               End If
               If instr(location(findit),strMdlFind)>0 then
               End If
          'If a location containing a serial number block was found then store it
          If intSerFoundAt<>-1 then
               If instr(tmp,chr(&H0a))>0 then
               End If
               'although it is not part of the edid spec it seems as though the
               'serial number will frequently be preceeded by &H00, this
               'compensates for that
               If left(tmpser,1)=chr(0) then tmpser=right(tmpser,len(tmpser)-1)
               tmpser="Not Found"
          End If
          'If a location containing a model number block was found then store it
          If intMdlFoundAt<>-1 then
               If instr(tmp,chr(&H0a))>0 then
               End If
               'although it is not part of the edid spec it seems as though the
               'serial number will frequently be preceeded by &H00, this
               'compensates for that
               If left(tmpmdl,1)=chr(0) then tmpmdl=right(tmpmdl,len(tmpmdl)-1)
               tmpmdl="Not Found"
          End If

          'Next get the mfg date
          Dim tmpmfgweek,tmpmfgyear,tmpmdt
          'the week of manufacture is stored at EDID offset &H10
          'the year of manufacture is stored at EDID offset &H11
          'and is the current year -1990
          'store it in month/year format          
          tmpmdt=month(dateadd("ww",tmpmfgweek,datevalue("1/1/" & tmpmfgyear))) & "/" & tmpmfgyear
          'Next get the edid version
          'the version is at EDID offset &H12
          Dim tmpEDIDMajorVer, tmpEDIDRev, tmpVer
          'the revision level is at EDID offset &H13
          'store it in month/year format          
          tmpver=chr(48+tmpEDIDMajorVer) & "." & chr(48+tmpEDIDRev)
          'Next get the mfg id
          'the mfg id is 2 bytes starting at EDID offset &H08
          'the id is three characters long.  using 5 bits to represent
          'each character.  the bits are used so that 1=A 2=B etc..
          'get the data
          Dim tmpEDIDMfg, tmpMfg
          dim Char1, Char2, Char3
          Dim Byte1, Byte2
          Char1=0 : Char2=0 : Char3=0 
          Byte1=asc(left(tmpEDIDMfg,1)) 'get the first half of the string 
          Byte2=asc(right(tmpEDIDMfg,1)) 'get the first half of the string
          'now shift the bits
          'shift the 64 bit to the 16 bit
          If (Byte1 and 64) > 0 then Char1=Char1+16 
          'shift the 32 bit to the 8 bit
          If (Byte1 and 32) > 0 then Char1=Char1+8 
          If (Byte1 and 16) > 0 then Char1=Char1+4 
          If (Byte1 and 8) > 0 then Char1=Char1+2 
          If (Byte1 and 4) > 0 then Char1=Char1+1 

          'the 2nd character uses the 2 bit and the 1 bit of the 1st byte
          If (Byte1 and 2) > 0 then Char2=Char2+16 
          If (Byte1 and 1) > 0 then Char2=Char2+8 
          'and the 128,64 and 32 bits of the 2nd byte
          If (Byte2 and 128) > 0 then Char2=Char2+4 
          If (Byte2 and 64) > 0 then Char2=Char2+2 
          If (Byte2 and 32) > 0 then Char2=Char2+1 

          'the bits for the 3rd character don't need shifting
          'we can use them as they are
          Char3=Char3+(Byte2 and 16) 
          Char3=Char3+(Byte2 and 8) 
          Char3=Char3+(Byte2 and 4) 
          Char3=Char3+(Byte2 and 2) 
          Char3=Char3+(Byte2 and 1) 
          tmpmfg=chr(Char1+64) & chr(Char2+64) & chr(Char3+64)
          'Next get the device id
          'the device id is 2bytes starting at EDID offset &H0a
          'the bytes are in reverse order.
          'this code is not text.  it is just a 2 byte code assigned
          'by the manufacturer.  they should be unique to a model
          Dim tmpEDIDDev1, tmpEDIDDev2, tmpDev
          If len(tmpEDIDDev1)=1 then tmpEDIDDev1="0" & tmpEDIDDev1
          If len(tmpEDIDDev2)=1 then tmpEDIDDev2="0" & tmpEDIDDev2
          tmpdev=tmpEDIDDev2 & tmpEDIDDev1
          'finally store all the values into the array
          'Kaplan adds code to avoid duplication...
          If Not InArray(tmpser,arrMonitorInfo,3) Then 
          End If 
     End If

'For now just a simple screen print will suffice for output.
'But you could take this output and write it to a database or a file
'and in that way use it for asset management.
i = 0
for tmpctr = 0 to intMonitorCount-1
	 If arrMonitorInfo(tmpctr,1) <> "" And arrMonitorInfo(tmpctr,0) <> "PNP" Then 
	 	If batch Then
	 		EchoAndLog strComputer & "," & arrMonitorInfo(tmpctr,4) & "," & _
		     arrMonitorInfo(tmpctr,3)& "," & arrMonitorInfo(tmpctr,0) & "," & _
		     message =  message & "Monitor " & chr(i+65) & ")" & VbCrLf & _
		     "Model Name: " & arrMonitorInfo(tmpctr,4) & VbCrLf & _
		     "Serial Number: " & arrMonitorInfo(tmpctr,3)& VbCrLf & _
		     "VESA Manufacturer ID: " & arrMonitorInfo(tmpctr,0) & VbCrLf & _
			 "Manufacture Date: " & arrMonitorInfo(tmpctr,2) & VbCrLf & VbCrLf 
		     'wscript.echo ".........." & "Device ID: " & arrMonitorInfo(tmpctr,1)
		     'wscript.echo ".........." & "EDID Version: " & arrMonitorInfo(tmpctr,5)
			     i = i + 1
    	 End If 
     End If 

If not batch Then
	MsgBox message, vbInformation + vbOKOnly,strComputer & " Monitor Info"
End If 

Function InArray(strValue,List,Col)
	Dim i
	For i = 0 to UBound(List)
		If List(i,col) = cstr(strValue) Then
			InArray = True
			Exit Function
		End If
	InArray = False 
End Function

Sub EchoAndLog (message)
'Echo output and write to log
	Wscript.Echo message
	AppendOut.WriteLine message
End Sub  

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi, for the most part, this is already set up in the script.  All you need to do is run this batch file:

for /F "tokens=*" %%A in (computers.txt) do cscript c:\scripts\GetMonitorInfo.vbs %%A

and it will pass each computer from the file, into the GetMonitorInfo.vbs script, and output the results to %userprofile%\desktop\MonitorInfo.csv

I haven't tested it, but try it out.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.