none
WMIMonitorID RRS feed

  • Question

  • i have written a VB script for computer inventory and i want it to pull the WMIMonitorID information. the issue i am having is how to convert the information from ASCII Decimal to Character.

    i get this information when i run the script:

    ManufacturerName: 68,69,76,0,0,0,0,0,0,0,0,0,0,0,0,0
    ProductCodeID: 52,48,50,48,0,0,0,0,0,0,0,0,0,0,0,0
    SerialNumberID: 67,53,53,51,72,56,57,80,65,65,55,50,0,0,0,0
    UserFriendlyName: 68,69,76,76,32,49,57,48,55,70,80,86,0

    from this:

      strManufacturerName = Join(objItem.ManufacturerName, ",")
             WScript.Echo "ManufacturerName: " & strManufacturerName
          strProductCodeID = Join(objItem.ProductCodeID, ",")
             WScript.Echo "ProductCodeID: " & strProductCodeID
          strSerialNumberID = Join(objItem.SerialNumberID, ",")
             WScript.Echo "SerialNumberID: " & strSerialNumberID
          strUserFriendlyName = Join(objItem.UserFriendlyName, ",")
             WScript.Echo "UserFriendlyName: " & strUserFriendlyName

    i have spent the last two days searching for some way of doing this but i am at a lost! this is the last part of the VB script that i need to finish it any help would be most appreciated!!!!

    Tuesday, May 15, 2012 1:40 PM

Answers

  • Here's a VBScript version:

    Function BytesToString(ByVal Bytes)
      Dim Result, N
      Result = ""
      For N = 0 To UBound(Bytes)
        If CInt(Bytes(N)) <> 0 Then
          Result = Result & Chr(Bytes(N))
        Else
          Exit For
        End If
      Next
      BytesToString = Result
    End Function
    
    Dim WMI, Monitors, Output, Monitor
    Set WMI = GetObject("winmgmts:{impersonationlevel=impersonate}!root/wmi")
    Set Monitors = WMI.InstancesOf("WmiMonitorID")
    Output = ""
    For Each Monitor In Monitors
      If Output <> "" Then
        Output = vbNewLine & Output
      End If
      Output = Output _
        & "Active: " & CStr(Monitor.Active) & vbNewLine _
        & "InstanceName: " & Monitor.InstanceName & vbNewLine _
        & "ManufacturerName: " & BytesToString(Monitor.ManufacturerName) & vbNewLine _
        & "ProductCodeID: " & BytesToString(Monitor.ProductCodeID) & vbNewLine _
        & "SerialNumberID: " & BytesToString(Monitor.SerialNumberID) & vbNewLine _
        & "UserFriendlyName: " & BytesToString(Monitor.UserFriendlyName) & vbNewLine _
        & "WeekOfManufacture: " & CStr(Monitor.WeekOfManufacture) & vbNewLine _
        & "YearOfManufacture: " & CStr(Monitor.YearOfManufacture)
    Next
    
    WScript.Echo Output
    

    Bill

    • Marked as answer by shane44 Tuesday, May 15, 2012 4:36 PM
    Tuesday, May 15, 2012 4:23 PM
    Moderator

All replies

  • Hi,

    What's the code you're using to get this information?

    Bill

    Tuesday, May 15, 2012 1:50 PM
    Moderator
  • i am using WMIMonittorID

    here is the whole section that i am using.

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
       Set colItems = objWMIService.ExecQuery("SELECT * FROM WmiMonitorID", "WQL", _
                                              wbemFlagReturnImmediately + wbemFlagForwardOnly)
    objTextFile.WriteLine

       For Each objItem In colItems
           objTextFile.WriteLine "Active: " & objItem.Active
           objTextFile.WriteLine "InstanceName: " & objItem.InstanceName
          strManufacturerName = Join(objItem.ManufacturerName, ",")
            objTextFile.WriteLine "ManufacturerName: " & strManufacturerName
          strProductCodeID = Join(objItem.ProductCodeID, ",")
            objTextFile.WriteLine "ProductCodeID: " & strProductCodeID
          strSerialNumberID = Join(objItem.SerialNumberID, ",")
            objTextFile.WriteLine "SerialNumberID: " & strSerialNumberID
          strUserFriendlyName = Join(objItem.UserFriendlyName, ",")
            objTextFile.WriteLine "UserFriendlyName: " & strUserFriendlyName
          objTextFile.WriteLine "UserFriendlyNameLength: " & objItem.UserFriendlyNameLength
          objTextFile.WriteLine "WeekOfManufacture: " & objItem.WeekOfManufacture
          objTextFile.WriteLine "YearOfManufacture: " & objItem.YearOfManufacture
          objTextFile.WriteLine
       Next

    Tuesday, May 15, 2012 3:27 PM
  • Hi,

    I did it in PowerShell:

    function Convert-BytesToString($bytes) {
      $result = ""
      for ( $n = 0; $n -lt $bytes.Length; $n++ ) {
        if ( $bytes[$n] -ne 0 ) {
          $result += [Char] $bytes[$n]
        }
        else {
          break
        }
      }
      $result
    }
    
    $monitors = Get-WmiObject -Class "WmiMonitorID" -Namespace "root\wmi"
    foreach ( $monitor in $monitors ) {
      $monitor | Select-Object Active,
        InstanceName,
        @{Name="ManufacturerName"; Expression={Convert-BytesToString $monitor.ManufacturerName}},
        @{Name="ProductCodeID"; Expression={Convert-BytesToString $monitor.ProductCodeID}},
        @{Name="SerialNumberID"; Expression={Convert-BytesToString $monitor.SerialNumberID}},
        @{Name="UserFriendlyName"; Expression={Convert-BytesToString $monitor.UserFriendlyName}},
        WeekOfManufacture,
        YearOfManufacture
    }
    

    Bill

    Tuesday, May 15, 2012 3:57 PM
    Moderator
  • Here's a VBScript version:

    Function BytesToString(ByVal Bytes)
      Dim Result, N
      Result = ""
      For N = 0 To UBound(Bytes)
        If CInt(Bytes(N)) <> 0 Then
          Result = Result & Chr(Bytes(N))
        Else
          Exit For
        End If
      Next
      BytesToString = Result
    End Function
    
    Dim WMI, Monitors, Output, Monitor
    Set WMI = GetObject("winmgmts:{impersonationlevel=impersonate}!root/wmi")
    Set Monitors = WMI.InstancesOf("WmiMonitorID")
    Output = ""
    For Each Monitor In Monitors
      If Output <> "" Then
        Output = vbNewLine & Output
      End If
      Output = Output _
        & "Active: " & CStr(Monitor.Active) & vbNewLine _
        & "InstanceName: " & Monitor.InstanceName & vbNewLine _
        & "ManufacturerName: " & BytesToString(Monitor.ManufacturerName) & vbNewLine _
        & "ProductCodeID: " & BytesToString(Monitor.ProductCodeID) & vbNewLine _
        & "SerialNumberID: " & BytesToString(Monitor.SerialNumberID) & vbNewLine _
        & "UserFriendlyName: " & BytesToString(Monitor.UserFriendlyName) & vbNewLine _
        & "WeekOfManufacture: " & CStr(Monitor.WeekOfManufacture) & vbNewLine _
        & "YearOfManufacture: " & CStr(Monitor.YearOfManufacture)
    Next
    
    WScript.Echo Output
    

    Bill

    • Marked as answer by shane44 Tuesday, May 15, 2012 4:36 PM
    Tuesday, May 15, 2012 4:23 PM
    Moderator
  • I have 2 computer

    One of them use ROOT\WMI\ms_409\WmimonitorID and the other is ROOT\WMI\WmimonitorID to get serial number from monitor.

    What is the difference? How can i know which pc which path uses? I made a monitor identifing dll that connect serial number to \\Display1....( screen.allscreen(x) )


    • Edited by wrickout Tuesday, February 12, 2019 4:35 PM
    Tuesday, February 12, 2019 4:18 PM
  • I have 2 computer

    One of them use ROOT\WMI\ms_409\WmimonitorID and the other is ROOT\WMI\WmimonitorID to get serial number from monitor.

    What is the difference? How can i know which pc which path uses? I made a monitor identifing dll that connect serial number to \\Display1....( screen.allscreen(x) )


    Please do not add questions to other users topics.  You must start your own question. Also do not add to old and closed topics.


    \_(ツ)_/

    Tuesday, February 12, 2019 6:51 PM