Jump to content

Help Modifying Code To Read Monitor Info


Go to solution Solved by dragan,

Recommended Posts

Hi All,

I need help modifying some code i found on the forums here.  Here is the link to the thread.  '?do=embed' frameborder='0' data-embedContent>>

First i would like to give credit to the people who wrote this.  Archrival and Rover (I think)

It reads the monitors EDID data from the registry, but it only returns the Model and Serial number.  I would like to modify it to return the Manufacturer as well.  (and the standard timings if someone is feeling really ambitious :P)

Here is the code.

;Collect EDID strings for all active monitors
$iCounterEDID = 0
Dim $asEDID[1]

$iCounterMonitorName = 1
Do
    $sMonitorName = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY", $iCounterMonitorName)
    If $sMonitorName <> "" Then
        $iCounterMonitorCode = 1
        Do
           ; Search 'monitor code' - 5&3aba5caf&0&10000080&01&00
            $sMonitorCode = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & $sMonitorName, $iCounterMonitorCode)
           ; Search Control folder - When available, the active monitor is found
            $iCounterMonitorControlFolder = 1
            Do
                $sMonitorControlFolder = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & $sMonitorName & "\" & $sMonitorCode, $iCounterMonitorControlFolder)
                If $sMonitorControlFolder == "Control" Then; Active monitor found!
                    $sMonitorEDIDRead = RegRead("HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & $sMonitorName & "\" & $sMonitorCode & "\Device Parameters", "EDID")
                    If $sMonitorEDIDRead <> "" Then
                        $sMonitorEDID = $sMonitorEDIDRead
                        $iCounterEDID = $iCounterEDID + 1
                        $asEDID[0] = $iCounterEDID
                        ReDim $asEDID[UBound($asEDID) + 1]
                        $asEDID[UBound($asEDID) - 1] = $sMonitorEDID; Add found EDID string to Array
                    EndIf
                EndIf
                $iCounterMonitorControlFolder = $iCounterMonitorControlFolder + 1; Increase counter to search for next folder
            Until $sMonitorControlFolder == ""
            $iCounterMonitorCode = $iCounterMonitorCode + 1; Increase counter to search for next 'monitor code' folder
        Until $sMonitorCode == ""
    EndIf
    $iCounterMonitorName = $iCounterMonitorName + 1; Increase counter to search for next monitor
Until $sMonitorName == ""


; Decrypt collected EDID strings - Thanks archrival
For $k = 1 To $asEDID[0]
    $sMonEDID = $asEDID[$k]
    If $sMonEDID <> "" Then
        $j = 0
        Dim $edidarray[StringLen($sMonEDID) ]
        $edidarray[0]= (StringLen($sMonEDID) / 2) + 1
        For $i = 1 To StringLen($sMonEDID) Step 2
            $j = $j + 1
            $edidarray[$j] = Dec(StringMid($sMonEDID, $i, 2))
        Next
        $ser = StringStripWS(_FindMonitorSerial(), 1 + 2)
        $name = StringStripWS(_FindMonitorName(), 1 + 2)
    Else
        $ser = ""
        $name = ""
    EndIf

    MsgBox(64, "Monitor " & $k, "MonitorSerial: " & $ser & @CRLF & "MonitorName: " & $name);Show MonitorSerial & MonitorName: no info? -> Your using a notebook right!
Next

; Functions

Func _FindMonitorSerial(); Thanks archrival
    $sernumstr = ""
    $sernum = 0
    For $i = 1 To (UBound($edidarray) / 2) - 4
        If $edidarray[$i] = "0" And $edidarray[$i + 1] = "0" And $edidarray[$i + 2] = "0" And $edidarray[$i + 3] = "255" And $edidarray[$i + 4] = "0" Then
            $sernum = $i + 4
        EndIf
    Next
    If $sernum <> 0 Then
        $endstr = 0
        $sernumstr = ""
        For $i = 1 To 13
            If $edidarray[$sernum + $i] = "10" Then
                $endstr = 1
            Else
                If $endstr = 0 Then
                    $sernumstr = $sernumstr & Chr($edidarray[$sernum + $i])
                EndIf
            EndIf
        Next
    Else
        $sernumstr = ""
    EndIf
    Return $sernumstr
EndFunc  ;==>_FindMonitorSerial

Func _FindMonitorName(); Thanks archrival
    $name = 0
    For $i = 1 To (UBound($edidarray) / 2) - 4
        If $edidarray[$i] = "0" And $edidarray[$i + 1] = "0" And $edidarray[$i + 2] = "252" And $edidarray[$i + 3] = "0" Then
            $name = $i + 3
        EndIf
    Next
    If $name <> 0 Then
        $endstr = 0
        $namestr = ""
        For $i = 1 To 13
            If $edidarray[$name + $i] = "10" Then
                $endstr = 1
            Else
                If $endstr = 0 Then
                    $namestr = $namestr & Chr($edidarray[$name + $i])
                EndIf
            EndIf
        Next
    Else
        $namestr = ""
    EndIf
    Return $namestr
EndFunc  ;==>_FindMonitorName 

I looked through it, and i dont even know where to start.  

Also, someone said you could just use this program and run it from command line.  But even that is a little over my pay grade. (Ive been using autoit for a week, no programming expierence)

Any help is greatly appreciated, even if its just a point in the right direction.  Im here to learn! :)

Link to comment
Share on other sites

Came up with new plan, will make new thread.  This script will not work anyway as it reads the registry to get the monitor info.  However, if you had two monitors hooked up and then unplugged one, this script would still show the monitor you just unplugged.  

Still want to give thanks to the people who wrote that script though. :)

You can close this thread now if you want.  

Link to comment
Share on other sites

  • Solution

You could have used >scriptomatic to get the code to read monitor info via WMI, and you can get manufacturer as well:
 

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DesktopMonitor", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
    For $objItem In $colItems
        $Output = $Output & "Availability: " & $objItem.Availability & @CRLF
        $Output = $Output & "Bandwidth: " & $objItem.Bandwidth & @CRLF
        $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
        $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF
        $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF
        $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF
        $Output = $Output & "Description: " & $objItem.Description & @CRLF
        $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF
        $Output = $Output & "DisplayType: " & $objItem.DisplayType & @CRLF
        $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF
        $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF
        $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
        $Output = $Output & "IsLocked: " & $objItem.IsLocked & @CRLF
        $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF
        $Output = $Output & "MonitorManufacturer: " & $objItem.MonitorManufacturer & @CRLF      ;<--------- manufacturer
        $Output = $Output & "MonitorType: " & $objItem.MonitorType & @CRLF
        $Output = $Output & "Name: " & $objItem.Name & @CRLF
        $Output = $Output & "PixelsPerXLogicalInch: " & $objItem.PixelsPerXLogicalInch & @CRLF
        $Output = $Output & "PixelsPerYLogicalInch: " & $objItem.PixelsPerYLogicalInch & @CRLF
        $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF
        $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0)
        $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF
        $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF
        $Output = $Output & "ScreenHeight: " & $objItem.ScreenHeight & @CRLF
        $Output = $Output & "ScreenWidth: " & $objItem.ScreenWidth & @CRLF
        $Output = $Output & "Status: " & $objItem.Status & @CRLF
        $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF
        $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF
        $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF
        if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
        $Output=""
    Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_DesktopMonitor" )
Endif


Func WMIDateStringToDate($dtmDate)
    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc
Link to comment
Share on other sites

 

You could have used >scriptomatic to get the code to read monitor info via WMI, and you can get manufacturer as well:

 

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DesktopMonitor", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
    For $objItem In $colItems
        $Output = $Output & "Availability: " & $objItem.Availability & @CRLF
        $Output = $Output & "Bandwidth: " & $objItem.Bandwidth & @CRLF
        $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
        $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF
        $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF
        $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF
        $Output = $Output & "Description: " & $objItem.Description & @CRLF
        $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF
        $Output = $Output & "DisplayType: " & $objItem.DisplayType & @CRLF
        $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF
        $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF
        $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
        $Output = $Output & "IsLocked: " & $objItem.IsLocked & @CRLF
        $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF
        $Output = $Output & "MonitorManufacturer: " & $objItem.MonitorManufacturer & @CRLF      ;<--------- manufacturer
        $Output = $Output & "MonitorType: " & $objItem.MonitorType & @CRLF
        $Output = $Output & "Name: " & $objItem.Name & @CRLF
        $Output = $Output & "PixelsPerXLogicalInch: " & $objItem.PixelsPerXLogicalInch & @CRLF
        $Output = $Output & "PixelsPerYLogicalInch: " & $objItem.PixelsPerYLogicalInch & @CRLF
        $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF
        $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0)
        $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF
        $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF
        $Output = $Output & "ScreenHeight: " & $objItem.ScreenHeight & @CRLF
        $Output = $Output & "ScreenWidth: " & $objItem.ScreenWidth & @CRLF
        $Output = $Output & "Status: " & $objItem.Status & @CRLF
        $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF
        $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF
        $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF
        if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
        $Output=""
    Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_DesktopMonitor" )
Endif


Func WMIDateStringToDate($dtmDate)
    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

 

Thanks Dragan.  I  had already looked into that but it doesn't return the data i need from the monitors i work with.  

Ive got it figured out now, made a script that uses EDIDW2K.exe to read the entire monitor EDID data and spit out a text file, then i just search for the strings i need.

Thanks again for the response, much appreicated. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...