Jump to content
Sign in to follow this  
archrival

Simple monitor serial number retriever

Recommended Posts

Fairly simple, requires newest beta version. This will ask you to enter a machine name (it defaults to your own) and then it will retrieve the Model Name and serial number of the monitor. Comments welcome.

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

_StrComputer()
If Ping($strComputer, 200) = 0 Then 
    MsgBox(0, "Error", $strComputer & " could not be reached, please enter another.")
    _StrComputer()
EndIf
_ObjWMI()

Func _ObjWMI()
    Global $objWMIService = ObjGet ("winmgmts:\\" & $strComputer & "\root\CIMV2")
    _ObjWMICheck()
EndFunc

Func _ObjWMICheck()
    If $objWMIService = "" Then
        MsgBox(0, "WMI Error", "WMI not running on " & $strComputer & ", please enter another computer name.")
        _StrComputer()
        _ObjWMI()
    EndIf
EndFunc

$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_DesktopMonitor", "WQL", _
        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

$j = 0
$msg = ""
If IsObj ($colItems) Then
    For $objItem In $colItems
        $PNPDeviceID = $objItem.PNPDeviceID
        $screenwidth = $objItem.ScreenWidth
        If $screenwidth = 0 Then ExitLoop
        $monedid = RegRead("\\" & $strComputer & "\HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum\" & $PNPDeviceID & "\Device Parameters", "EDID")
        Dim $edidarray[StringLen($monedid) ]
        $edidarray[0]= (StringLen($monedid) / 2) + 1
        For $i = 1 To StringLen($monedid) Step 2
            $j = $j + 1
            $edidarray[$j] = Dec(StringMid($monedid, $i, 2))
        Next
    Next
    $ser = _FindMonitorSerial()
    $name = _FindMonitorName()
    MsgBox(0, "Monitor Information", "Monitor Name: " & $name & @CRLF & "Serial Number: " & $ser)
Else
    MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_DesktopMonitor")
EndIf

Func _FindMonitorSerial()
    $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

Func _FindMonitorName()
    $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

Func _StrComputer()
    Global $strComputer = InputBox("Computer Name", "Enter Computer Name:", StringLower(@ComputerName), "", 100, 120)
    If @error = 1 Then Exit
EndFunc
Edited by archrival

Share this post


Link to post
Share on other sites

great idea to create this script. but it doesn't work for me though.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

the above screenshot was from a Compaq monitor and it didn't work. but i tried on a Phillips 107S5 monitor and it worked fine!

gd job!


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

the above screenshot was from a Compaq monitor and it didn't work. but i tried on a Phillips 107S5 monitor and it worked fine!

gd job!

<{POST_SNAPBACK}>

Yeah, not every monitor will return the serial number. My monitor at home has the serial number 000001, I imagine all KDS VS-190 monitors return that same serial number. I wrote this script because we have Dell flat panels and I need to make sure they stay with the particular PC. When I rolled out the PCs, I forgot to mark down the monitor serial number. I'm an efficient type of lazy, yes I figured out how to retrieve it from my desk, but I don't feel like going around to all the PCs and writing down the serial numbers. So this works for me, most of the code I post on here is stuff I need for my job and I just like to share.

Share this post


Link to post
Share on other sites

Yeah, not every monitor will return the serial number. My monitor at home has the serial number 000001, I imagine all KDS VS-190 monitors return that same serial number. I wrote this script because we have Dell flat panels and I need to make sure they stay with the particular PC. When I rolled out the PCs, I forgot to mark down the monitor serial number. I'm an efficient type of lazy, yes I figured out how to retrieve it from my desk, but I don't feel like going around to all the PCs and writing down the serial numbers. So this works for me, most of the code I post on here is stuff I need for my job and I just like to share.

That's exact what I'm looking for, but it doesn't work on my pc!!!

No model and serial is shown!

It's stored, because Everest and AIDA shows the information...

Do you have any idea why?

I'm using the latest beta 3.1.1.87

thanks

Share this post


Link to post
Share on other sites

That's exact what I'm looking for, but it doesn't work on my pc!!!

No model and serial is shown!

It's stored, because Everest and AIDA shows the information...

Do you have any idea why?

I'm using the latest beta 3.1.1.87

thanks

I'm not too sure, this code has to decode what is already stored in Windows. I'm also not sure if those programs use WMI, I doubt it. Just make sure WMI is running and you have read access to "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum\DISPLAY". You could check the registry entries under Display for Device Parameters, that is decoded to determine the Serial and Name. If it exists, then I'm not sure, I'm willing to bet it does not. Those programs could possibly read the DDC/EDID information directly, that may be possible now via DLL calls, but that's not something I'd be able to figure out anytime soon.

I changed around the code a little, it's basically the same, I just don't ask to enter a new PC name if the entered one fails.

$strComputer = InputBox("Computer Name", "Enter Computer Name:", StringLower(@ComputerName), "", 100, 120)
If @error = 1 Then Exit
        
If Ping($strComputer, 200) = 0 Then
    MsgBox(0, "Error", $strComputer & " could not be reached.")
    Exit
EndIf

$objWMIService = ObjGet ("winmgmts:\\" & $strComputer & "\root\CIMV2")

If $objWMIService = "" Then
    MsgBox(0, "WMI Error", "WMI not running on " & $strComputer & ".")
    Exit
EndIf

$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_DesktopMonitor", "WQL", _
        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

$j = 0
$msg = ""
If IsObj ($colItems) Then
    For $objItem In $colItems
        $PNPDeviceID = $objItem.PNPDeviceID
        $screenwidth = $objItem.ScreenWidth
        If $screenwidth = 0 Then ExitLoop
        $monedid = RegRead("\\" & $strComputer & "\HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum\" & $PNPDeviceID & "\Device Parameters", "EDID")
        Dim $edidarray[StringLen($monedid) ]
        $edidarray[0]= (StringLen($monedid) / 2) + 1
        For $i = 1 To StringLen($monedid) Step 2
            $j = $j + 1
            $edidarray[$j] = Dec(StringMid($monedid, $i, 2))
        Next
    Next
    $ser = _FindMonitorSerial()
    $name = _FindMonitorName()
    MsgBox(0, "Monitor Information", "Monitor Name: " & $name & @CRLF & "Serial Number: " & $ser)
Else
    MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_DesktopMonitor")
EndIf

Func _FindMonitorSerial()
    $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

Func _FindMonitorName()
    $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

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...