Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

VB Script to note if PC Monitor is active

$
0
0

Ok I found a script (its beautiful) that grabs the EDID info I want from all of our monitors and creates a local text file that I can use for remote inventory. However, It doesn't note if the monitor is active or not and so just dumps a huge list of all monitors ever attached to the host pc. I don't want to delete this extra info as it may be helpful to track a monitor in the future.

I've figured out that if a monitor is active then it will have a "Control" registry sub-key like this: "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY\DEL4026\5&2e1002ed&0&UID770\Control". I just need some help with how to get the sub-key "Control" to be noted in the output file.

I know enough VBS so that I can usually tweak a script to suit my needs, but this is a little complex for me. I've been tinkering for days and I just can't figure it out. Here's the VBScript and hanks for your time in advance!

' Script modified from
' http://www.robvanderwoude.com/files/dispedid_vbs.txt

Option Explicit

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

'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_DWORD_LITTLE_ENDIAN = 4
Const REG_DWORD_BIG_ENDIAN    = 5
Const REG_LINK                = 6
Const REG_MULTI_SZ            = 7
Const REG_RESOURCE_LIST       = 8

'FileSystemObject OpenTextFile constants
Const ForReading              = 1
Const ForWriting              = 2
Const ForAppending            = 8

If WScript.Arguments.Count > 0 Then Syntax

strComputer = "."
strMsg      = ""

On Error Resume Next
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
          Next
        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
            If ((strSerial <> vbNull) And (strSerial <> "")) Then
              If StrMsg = "" Then
                strMsg = "Manufacturer: " & strMfg & vbCrLf _
                & "Description: " & strDeviceDesc & vbCrLf _
                & "Model (EDID): " & strModel & vbCrLf _
                & "Serial# (EDID): " & strSerial & vbCrLf
              Else
                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
      Next
    End If
  Next
End If

If ((StrMsg = vbNull) Or (StrMsg = "")) Then
  WScript.Quit
End If

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFso = WScript.CreateObject("Scripting.FileSystemObject")

strOutputFile = "C:\Windows\Temp\Monitor-info.txt"

If objFso.FolderExists("C:\windows\temp") then
  set objOutputFile = objFso.OpenTextFile(strOutputFile, ForWriting, True)
  'WScript.Echo strMsg
  objOutputFile.Write strMsg
  objOutputFile.Close
End If

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
  Next

  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
    Next
    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

---------

Here is some sample output. In some instances the same monitor appears on hundreds of pcs.

Manufacturer: (Standard monitor types)
Description: Generic PnP Monitor
Model (EDID): DELL 1908FP
Serial# (EDID): UW042???????

Manufacturer: Dell Inc.
Description: Dell 1908FP(Digital)
Model (EDID): DELL 1908FP
Serial# (EDID): UW042???????

Manufacturer: Dell Inc.
Description: Dell 1908FP(Digital)
Model (EDID): DELL 1908FP
Serial# (EDID): UW042???????



Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>