Go Premium for a chance to win a PS4. Enter to Win


Want to get monitor information using WMI and send it to a database

Posted on 2012-03-26
Medium Priority
Last Modified: 2012-08-14
I found the code below written by Rob van der Woude that displays the information that I want. What I am trying to do is send this information into a mysql database using a PHP script but I am new to WMI and VBS so not sure how this would be done. I use OpenAudit to get information from all my computers but the vbs script that is used only displays one monitor and we have alot of users who have a dual monitor setup and need all the information for each one. Thank you in advance for the help.

'Option Explicit

Dim blnControl
Dim i, j, k
Dim arrControl, arrKeys, arrRawEDID, arrSubKeys
Dim objReg, wshShell
Dim strComputer, strDeviceDesc, strMfg, strModel, strMsg, strKeyPath, strSerial, strSubKeyPath, strSubSubKeyPath

'Hive Constants
Const HKEY_CLASSES_ROOT       = &H80000000
Const HKEY_CURRENT_USER       = &H80000001
Const HKEY_LOCAL_MACHINE      = &H80000002
Const HKEY_USERS              = &H80000003
Const HKEY_PERFORMANCE_DATA   = &H80000004
Const HKEY_CURRENT_CONFIG     = &H80000005
Const HKEY_DYN_DATA           = &H80000006

'RegFormat Constants
Const REG_NONE                = 0
Const REG_SZ                  = 1
Const REG_EXPAND_SZ           = 2
Const REG_BINARY              = 3
Const REG_DWORD               = 4
Const REG_LINK                = 6
Const REG_MULTI_SZ            = 7
Const REG_RESOURCE_LIST       = 8

If WScript.Arguments.Count > 0 Then Syntax

strComputer = ""
strMsg      = ""

Set objReg = GetObject( "winmgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/default:StdRegProv" )

strKeyPath = "SYSTEM\CurrentControlSet\Enum\DISPLAY"
objReg.EnumKey  HKEY_LOCAL_MACHINE, strKeyPath, arrKeys

If IsArray( arrKeys ) Then
	For i = 0 To UBound( arrKeys )
		strSubKeyPath = strKeyPath & "\" & arrKeys( i )
		objReg.EnumKey  HKEY_LOCAL_MACHINE, strSubKeyPath, arrSubKeys
		If IsArray( arrSubKeys ) Then
			For j = 0 To UBound( arrSubKeys )
				strSubSubKeyPath = strSubKeyPath & "\" & arrSubKeys( j )
				objReg.EnumKey  HKEY_LOCAL_MACHINE, strSubSubKeyPath, arrSub2
				blnControl = False
				If IsArray( arrSub2 ) Then
					For k = 0 To UBound( arrSub2 )
						If arrSub2(k) = "Control" Then blnControl = True
				End If
				If blnControl Then
					objReg.GetStringValue HKEY_LOCAL_MACHINE, strSubSubKeyPath, "Mfg", strMfg
					If IsNull( strMfg ) Then strMfg = "unknown"
					If InStr( strMfg, ";" ) Then strMfg = Mid( strMfg, InStr( strMfg, ";" ) + 1 )
					objReg.GetStringValue HKEY_LOCAL_MACHINE, strSubSubKeyPath, "DeviceDesc", strDeviceDesc
					If InStr( strDeviceDesc, ";" ) Then strDeviceDesc = Mid( strDeviceDesc, InStr( strDeviceDesc, ";" ) + 1 )
					objReg.GetBinaryValue HKEY_LOCAL_MACHINE, strSubSubKeyPath & "\Device Parameters", "BAD_EDID", arrBadEDID
					If Not IsArray( arrBadEDID ) Then
						objReg.GetBinaryValue HKEY_LOCAL_MACHINE, strSubSubKeyPath & "\Device Parameters", "EDID", arrRawEDID
						If IsArray( arrRawEDID ) Then
							Test 54
							Test 72
							Test 90
							Test 108
						End If
						strMsg = strMsg & vbCrLf _
						        & "Manufacturer   = " & strMfg        & vbCrLf _
						        & "Description    = " & strDeviceDesc & vbCrLf _
						        & "Model   (EDID) = " & strModel      & vbCrLf _
						        & "Serial# (EDID) = " & strSerial     & vbCrLf
					End If
				End If
		End If
End If

WScript.Echo strMsg

Sub Test( ByVal myIndex )
	Dim idx, arrTemp, arrTestModel, arrTestSerial, blnModel, blnSerial, strTemp
	arrTestModel  = Split( "0 0 0 252" )
	arrTestSerial = Split( "0 0 0 255" )
	blnModel      = True
	blnSerial     = True

	For idx = 0 To 3
		If CInt( arrTestModel( idx )  ) <> CInt( arrRawEDID( idx + myIndex ) ) Then blnModel  = False
		If CInt( arrTestSerial( idx ) ) <> CInt( arrRawEDID( idx + myIndex ) ) Then blnSerial = False

	If blnModel Or blnSerial Then
		For idx = 4 To 17
			Select Case arrRawEDID( myIndex + idx )
				Case 0
					strTemp = strTemp & " "
				Case 7
					strTemp = strTemp & " "
				Case 10
					strTemp = strTemp & " "
				Case 13
					strTemp = strTemp & " "
				Case Else
					strTemp = strTemp & Chr( arrRawEDID( myIndex + idx ) )
			End Select
		strTemp = Trim( strTemp )
		' The following lines are disabled because they truncate model names at the first space
		'If InStr( strTemp, " " ) Then
		'	arrTemp = Split( strTemp, " " )
		'	strTemp = arrTemp(0)
		'End If
		If blnModel  Then strModel  = strTemp
		If blnSerial Then strSerial = strTemp
	End If
End Sub

Sub Syntax
	strMsg = vbCrLf _
	       & "DispEDID.vbs,  Version 2.30" _
	       & vbCrLf _
	       & "Read and parse monitor EDID asset information from the registry" _
	       & vbCrLf & vbCrLf _
	       & "Usage:  DISPEDID.VBS" _
	       & vbCrLf & vbCrLf _
	       & "Based on a script by Michael Baird (link no longer available)" _
	       & vbCrLf & vbCrLf _
	       & "(Re)written by Rob van der Woude" _
	       & vbCrLf _
	       & "http://www.robvanderwoude.com"
	WScript.Echo strMsg
	WScript.Quit 1
End Sub

Open in new window

Question by:maximus81
  • 3
LVL 43

Accepted Solution

Rob earned 2000 total points
ID: 37769685
I will put forward my suggestion though I understand if you want to pursue the avenue you have already taken.  I am using LANSweeper to do exactly what you want and it is well maintained, updated regularly and uses WMI (http://www.lansweeper.com/).  If it's not what you want please ignore  :) just don't reinventing the wheel if you don't have to!
LVL 35

Expert Comment

by:Robert Schutt
ID: 37805315
I just ran the script and it did give information about both my attached monitors. Is it possible that OpenAudit is not returning the same data as you would get running this script locally?

If you can't use a product like mentioned by @tagit I would say first check that, maybe by writing the info you get for a specific computer into a file and then run the script locally on that computer to check for differences.

Author Comment

ID: 37805655
What version of Openaudit are you running?
LVL 35

Expert Comment

by:Robert Schutt
ID: 37805762
I don't. I ran the script locally for my computer only and it displayed the correct information. That's why I suggested the difference might be in the fact that you do use OpenAudit and the data it gives you for a specific computer is possibly not the same as when you would run the script on the computer directly. I don't know if that's a possibility (haven't worked with OpenAudit yet) but I thought it would be an easy check. Sort of a first step to ruling some things out.
LVL 35

Expert Comment

by:Robert Schutt
ID: 37806151
For the second part of the quest, putting this info in a MySQL database, there is an example that should translate 1:1 to VB script (it's in ASP) here: http://webcheatsheet.com/ASP/database_connection_to_MySQL.php 

Or, if the database is on an external server you can post the data to a php page from the script (using the "MSXML2.XMLHTTP" object) and update the database from there, which could be a lot easier.

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we’ll look at how to deploy ProxySQL.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question