Sign in to follow this  
Followers 0
gcue

clearing previous query

3 posts in this topic

#1 ·  Posted (edited)

anytime i enter a new asset, i keep getting the arraydisplay results from the previous asset entered....

any ideas?

(credit goes to rover for the findmonitor function - thanks rover!)

#539190

Global $Debug = True ; change to False or comment out/remove ConsoleWrite() lines if debugging to console not needed

Global $iCounterEDID = 0
Global $asEDID[1], $edidarray[1], $error1, $error2, $error3
Global $iCounterMonitorName = 1, $iCounterMonitorCode, $iCounterMonitorControlFolder
Global $sMonitorName, $sMonitorCode, $sMonitorControlFolder, $sMonitorEDIDRead, $ser, $name, $j
Global $monitors_found[1][1]

GUICreate(@ScriptName, 320, 100)

GUICtrlCreateLabel("Enter asset:", 60, 10)
$asset = GUICtrlCreateInput("", 40, 30, 130, 20, $ES_UPPERCASE)

$OK_btn = GUICtrlCreateButton("OK", 175, 30, 40, 20, 0x0300)
GUICtrlSetOnEvent(-1, "FindMonitors")

$CLOSE_btn = GUICtrlCreateButton("CLOSE", 220, 30, 80, 20, 0x0300);13
GUICtrlSetOnEvent(-1, "Xbutton")

GUISetOnEvent($GUI_EVENT_CLOSE, "Xbutton")

GUISetState()

While 1
    Sleep(10)
WEnd

Func FindMonitors()

    $asset = GUICtrlRead($asset)

    Do
        $sMonitorName = RegEnumKey("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY", $iCounterMonitorName)
        $error1 = @error
        If $Debug Then ConsoleWrite(@CRLF & '@@ Debug(' & @ScriptLineNumber & ') : $sMonitorName = ' & _
                StringStripWS($sMonitorName, 2) & @CRLF & '>Error code: ' & $error1 & @CRLF)
        If $sMonitorName <> "" Then
            $iCounterMonitorCode = 1
            Do
                ; Search 'monitor code' - e.g. 5&3aba5caf&0&10000080&01&00
                $sMonitorCode = RegEnumKey("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & _
                        $sMonitorName, $iCounterMonitorCode)
                $error2 = @error
                If $Debug Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sMonitorCode = ' & _
                        StringStripWS($sMonitorCode, 2) & @CRLF & '>Error code: ' & $error2 & @CRLF)
                ; Search Control folder - When available, the active monitor is found
                $iCounterMonitorControlFolder = 1

                Do
                    $sMonitorControlFolder = RegEnumKey("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & _
                            $sMonitorName & "\" & $sMonitorCode, $iCounterMonitorControlFolder)
                    $error3 = @error
                    If $Debug Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sMonitorControlFolder = ' & _
                            StringStripWS($sMonitorControlFolder, 2) & @CRLF & '>Error code: ' & $error3 & @CRLF)
                    If $sMonitorControlFolder == "Control" Then; Active monitor found!

                        Switch RegEnumVal("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & $sMonitorName & _
                                "\" & $sMonitorCode & "\Device Parameters", 1)
                            Case "EDID"
                                $sMonitorEDIDRead = RegRead("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & _
                                        $sMonitorName & "\" & $sMonitorCode & "\Device Parameters", "EDID")
                                If $sMonitorEDIDRead <> "" Then
                                    $iCounterEDID += 1
                                    $asEDID[0] = $iCounterEDID
                                    ReDim $asEDID[UBound($asEDID) + 1]
                                    $asEDID[UBound($asEDID) - 1] = $sMonitorEDIDRead; Add found EDID string to Array
                                EndIf
                            Case "BAD_EDID"
                                $iCounterEDID += 1
                                $asEDID[0] = $iCounterEDID
                                ReDim $asEDID[UBound($asEDID) + 1]
                                $asEDID[UBound($asEDID) - 1] = "BAD_EDID"; Add BAD_EDID string to Array
                            Case Else
                        EndSwitch
                    EndIf
                    $iCounterMonitorControlFolder += 1; Increase counter to search for next folder
                Until $error3 <> 0
                $iCounterMonitorCode += 1; Increase counter to search for next 'monitor code' folder
            Until $error2 <> 0
        EndIf
        $iCounterMonitorName += 1; Increase counter to search for next monitor
    Until $error1 <> 0

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

        If $ser <> "BAD_EDID" And $ser <> "" Then

            ReDim $monitors_found[UBound($monitors_found) + 1][1]

            $monitors_found[UBound($monitors_found) - 1][0] = $ser

            $monitors_found[0][0] = UBound($monitors_found) - 1

        EndIf
    Next

    _ArrayDisplay($monitors_found)

EndFunc   ;==>FindMonitors
Edited by gcue

Share this post


Link to post
Share on other sites



Just a stab in the dark here.. code is missing

Func FindMonitors()

    Local $monitors_found[1][1]
    $asset = GUICtrlRead($asset)

    Do
        $sMonitorName = RegEnumKey("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY", $iCounterMonitorName)
        $error1 = @error
        If $Debug Then ConsoleWrite(@CRLF & '@@ Debug(' & @ScriptLineNumber & ') : $sMonitorName = ' & _
                StringStripWS($sMonitorName, 2) & @CRLF & '>Error code: ' & $error1 & @CRLF)
        If $sMonitorName <> "" Then
            $iCounterMonitorCode = 1
            Do
                ; Search 'monitor code' - e.g. 5&3aba5caf&0&10000080&01&00
                $sMonitorCode = RegEnumKey("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & _
                        $sMonitorName, $iCounterMonitorCode)
                $error2 = @error
                If $Debug Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sMonitorCode = ' & _
                        StringStripWS($sMonitorCode, 2) & @CRLF & '>Error code: ' & $error2 & @CRLF)
                ; Search Control folder - When available, the active monitor is found
                $iCounterMonitorControlFolder = 1

                Do
                    $sMonitorControlFolder = RegEnumKey("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & _
                            $sMonitorName & "\" & $sMonitorCode, $iCounterMonitorControlFolder)
                    $error3 = @error
                    If $Debug Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sMonitorControlFolder = ' & _
                            StringStripWS($sMonitorControlFolder, 2) & @CRLF & '>Error code: ' & $error3 & @CRLF)
                    If $sMonitorControlFolder == "Control" Then; Active monitor found!

                        Switch RegEnumVal("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & $sMonitorName & _
                                "\" & $sMonitorCode & "\Device Parameters", 1)
                            Case "EDID"
                                $sMonitorEDIDRead = RegRead("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & _
                                        $sMonitorName & "\" & $sMonitorCode & "\Device Parameters", "EDID")
                                If $sMonitorEDIDRead <> "" Then
                                    $iCounterEDID += 1
                                    $asEDID[0] = $iCounterEDID
                                    ReDim $asEDID[UBound($asEDID) + 1]
                                    $asEDID[UBound($asEDID) - 1] = $sMonitorEDIDRead; Add found EDID string to Array
                                EndIf
                            Case "BAD_EDID"
                                $iCounterEDID += 1
                                $asEDID[0] = $iCounterEDID
                                ReDim $asEDID[UBound($asEDID) + 1]
                                $asEDID[UBound($asEDID) - 1] = "BAD_EDID"; Add BAD_EDID string to Array
                            Case Else
                        EndSwitch
                    EndIf
                    $iCounterMonitorControlFolder += 1; Increase counter to search for next folder
                Until $error3 <> 0
                $iCounterMonitorCode += 1; Increase counter to search for next 'monitor code' folder
            Until $error2 <> 0
        EndIf
        $iCounterMonitorName += 1; Increase counter to search for next monitor
    Until $error1 <> 0

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

        If $ser <> "BAD_EDID" And $ser <> "" Then

            ReDim $monitors_found[UBound($monitors_found) + 1][1]

            $monitors_found[UBound($monitors_found) - 1][0] = $ser

            ;$monitors_found[0][0] = UBound($monitors_found) - 1

        EndIf
    Next

    _ArrayDisplay($monitors_found)

    $monitors_found = ""

EndFunc   ;==>FindMonitors

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

actually i think its teh asset thats not getting cleared.

here's the entire scripts in its entirety (sorry always try to make it an easy read - efforts are backfiring!)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=clipboard.ico
#AutoIt3Wrapper_Outfile=Inventory Helper.exe
#AutoIt3Wrapper_Res_Fileversion=0.1
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)

Global $DELIM = @TAB; Change delimiter here
Global $avLines[1]
Global $sFile = "gvo_extract_ip.txt"
Global $AltirisBuilt = False, $avOut, $asset, $serialno, $monitors

Global $Debug = True ; change to False or comment out/remove ConsoleWrite() lines if debugging to console not needed

Global $iCounterEDID = 0
Global $asEDID[1], $edidarray[1], $error1, $error2, $error3
Global $iCounterMonitorName = 1, $iCounterMonitorCode, $iCounterMonitorControlFolder
Global $sMonitorName, $sMonitorCode, $sMonitorControlFolder, $sMonitorEDIDRead, $ser, $name, $j
Global $ver = ("InventoryHelper v" & FileGetVersion(@ScriptName))

GUICreate($ver, 320, 80)

GUICtrlCreateLabel("Enter asset:", 40, 10)
$asset = GUICtrlCreateInput("", 40, 30, 130, 20, $ES_UPPERCASE)

$OK_btn = GUICtrlCreateButton("OK", 175, 30, 40, 20, 0x0300)
GUICtrlSetOnEvent(-1, "FindMonitors")

$CLOSE_btn = GUICtrlCreateButton("CLOSE", 220, 30, 70, 20, 0x0300);13
GUICtrlSetOnEvent(-1, "Xbutton")

$status = GUICtrlCreateLabel("", 10, 60, 300, 25)

GUISetOnEvent($GUI_EVENT_CLOSE, "Xbutton")

GUISetState()

While 1
    Sleep(1)
WEnd

Func FindMonitors()

    GUICtrlSetData($status, "Identifying Monitors on PC")

Local $monitors_found[1][1]
    $asset = GUICtrlRead($asset)

    Do
        $sMonitorName = RegEnumKey("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY", $iCounterMonitorName)
        $error1 = @error
        If $Debug Then ConsoleWrite(@CRLF & '@@ Debug(' & @ScriptLineNumber & ') : $sMonitorName = ' & _
                StringStripWS($sMonitorName, 2) & @CRLF & '>Error code: ' & $error1 & @CRLF)
        If $sMonitorName <> "" Then
            $iCounterMonitorCode = 1
            Do
                ; Search 'monitor code' - e.g. 5&3aba5caf&0&10000080&01&00
                $sMonitorCode = RegEnumKey("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & _
                        $sMonitorName, $iCounterMonitorCode)
                $error2 = @error
                If $Debug Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sMonitorCode = ' & _
                        StringStripWS($sMonitorCode, 2) & @CRLF & '>Error code: ' & $error2 & @CRLF)
                ; Search Control folder - When available, the active monitor is found
                $iCounterMonitorControlFolder = 1

                Do
                    $sMonitorControlFolder = RegEnumKey("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & _
                            $sMonitorName & "\" & $sMonitorCode, $iCounterMonitorControlFolder)
                    $error3 = @error
                    If $Debug Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sMonitorControlFolder = ' & _
                            StringStripWS($sMonitorControlFolder, 2) & @CRLF & '>Error code: ' & $error3 & @CRLF)
                    If $sMonitorControlFolder == "Control" Then; Active monitor found!

                        Switch RegEnumVal("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & $sMonitorName & _
                                "\" & $sMonitorCode & "\Device Parameters", 1)
                            Case "EDID"
                                $sMonitorEDIDRead = RegRead("\\" & $asset & "\HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\" & _
                                        $sMonitorName & "\" & $sMonitorCode & "\Device Parameters", "EDID")
                                If $sMonitorEDIDRead <> "" Then
                                    $iCounterEDID += 1
                                    $asEDID[0] = $iCounterEDID
                                    ReDim $asEDID[UBound($asEDID) + 1]
                                    $asEDID[UBound($asEDID) - 1] = $sMonitorEDIDRead; Add found EDID string to Array
                                EndIf
                            Case "BAD_EDID"
                                $iCounterEDID += 1
                                $asEDID[0] = $iCounterEDID
                                ReDim $asEDID[UBound($asEDID) + 1]
                                $asEDID[UBound($asEDID) - 1] = "BAD_EDID"; Add BAD_EDID string to Array
                            Case Else
                        EndSwitch
                    EndIf
                    $iCounterMonitorControlFolder += 1; Increase counter to search for next folder
                Until $error3 <> 0
                $iCounterMonitorCode += 1; Increase counter to search for next 'monitor code' folder
            Until $error2 <> 0
        EndIf
        $iCounterMonitorName += 1; Increase counter to search for next monitor
    Until $error1 <> 0

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

        If $ser <> "BAD_EDID" And $ser <> "" Then

            ReDim $monitors_found[UBound($monitors_found) + 1][1]

            $monitors_found[UBound($monitors_found) - 1][0] = $ser

            $monitors_found[0][0] = UBound($monitors_found) - 1

        EndIf
    Next

    $monitors = _ArrayUnique($monitors_found)
    _ArrayDisplay($monitors)

    UserLookup()

EndFunc   ;==>FindMonitors

Func UserLookup()

    If $AltirisBuilt = False Then
        AltirisBuild()
    EndIf

    GUICtrlSetData($status, "Comparing Actual Data to Altiris Data")

    $sn_found = False
    $owner = ""

    For $x = 2 To UBound($monitors) - 1

        ;pull asset/owner based on serial no
        For $u = 1 To $avOut[0][0]

            If StringInStr($avOut[$u][6], $monitors[$x]) <> 0 Then

                $owner = $avOut[$u][13]

                If $avOut[$u][13] = "" Then
                    $owner = $avOut[$u][18]
                EndIf

                If $avOut[$u][18] = "" Then
                    $owner = "There is no registered Altiris owner, please update Altiris!"
                EndIf

                MsgBox(0, "", "serial: " & $avOut[$u][6] & @CRLF & _
                        "asset: " & $avOut[$u][0] & @CRLF & _
                        "owner: " & $owner)

                $sn_found = True
            EndIf

        Next
    Next

    GUICtrlSetData($status, "")

    If $sn_found = False Then
        MsgBox(0, "", GUICtrlRead($serialno) & " was not found in database.")
    EndIf

EndFunc   ;==>UserLookup

Func AltirisBuild()

    GUICtrlSetData($status, "Building Altiris Array")

    ; Read file in binary mode
    $hFile = FileOpen($sFile, 16)
    $binFileData = FileRead($hFile)
    FileClose($hFile)

    ; Change nulls
    $sFileData = BinaryToString($binFileData, 1)
    $sFileData = StringReplace($sFileData, Chr(0), "<null>")

    ; Split lines
    $avLines = StringSplit($sFileData, @CRLF, 1)

    Global $avOut[$avLines[0] + 1][2] = [[$avLines[0], ""]]; Start out with minimum two columns

    ; First loop - for each row
    For $n = 1 To $avLines[0]
        ; Split the line
        $avSplit = StringSplit($avLines[$n], $DELIM)

        ; Test if more columns are needed
        If $avSplit[0] > UBound($avOut, 2) Then ReDim $avOut[$avLines[0] + 1][$avSplit[0]]

        ; Second loop for each column
        For $x = 1 To $avSplit[0]
            $avOut[$n][$x - 1] = $avSplit[$x]
        Next
    Next

    $AltirisBuilt = True

EndFunc   ;==>AltirisBuild

Func _FindMonitorSerial(); Thanks archrival
    Local $sernumstr = "", $sernum = 0, $endstr
    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
        For $i = 1 To 13
            If $edidarray[$sernum + $i] = "10" Then
                $endstr = 1
            Else
                If $endstr = 0 Then
                    $sernumstr &= Chr($edidarray[$sernum + $i])
                EndIf
            EndIf
        Next
    EndIf
    Return $sernumstr
EndFunc   ;==>_FindMonitorSerial

Func Xbutton()
    Exit
EndFunc   ;==>Xbutton

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  
Followers 0