Client Management Suite

Expand all | Collapse all

Custom inventory USB devices

  • 1.  Custom inventory USB devices

    Posted 02-05-2020 04:57 AM

    Hi all,
    I'm trying to put together a custom inventory to report any USB devices,using VB script.
    I'm not familiar with VB code and it's quite difficult to debug the script outsite Altiris server.
    I hope you can help me to find the errors or suggest a better solution to achieve it, because it's not working. The report returns no value.


    On Altiris console side, I already created my custom class (USB_devices) and each attribute.

    Below the script. The first part "works" but I'm not sure about the second part.

    Option Explicit
    Dim oWMISrv, collDvcs, collUSBDvcs, iUSBDvc , iDvc, sDvcID, sPID, sVID

    Function ReplaceX(ByVal sValue, ByVal sPattern, ByVal sNValue)
    Dim oReg : Set oReg = New RegExp
        oReg.Pattern = sPattern
        ReplaceX = oReg.Replace(sValue, sNValue)
    Set oReg = Nothing
    End Function

    Set oWMISrv = GetObject("winmgmts:\\.\root\cimv2")
    Set collDvcs = oWMISrv.ExecQuery("Select * From Win32_USBControllerDevice")

    For Each iDvc In collDvcs
    If InStr(iDvc.Dependent, "VID_") Then ' Except keychain drives

            sDvcID = ReplaceX(iDvc.Dependent, ".*""(.*)""", "$1")
            sPID = ReplaceX(sDvcID, ".*PID_([^\\]*).*", "$1")
            sVID = ReplaceX(sDvcID, ".*VID_([^&]*).*", "$1")

    Set collUSBDvcs = oWMISrv.ExecQuery _
            ("Select * From Win32_PnPEntity Where DeviceID = '" & sDvcID & "'")
    For Each iUSBDvc in collUSBDvcs
                Wscript.Echo "Name : "& iUSBDvc.Name       
                Wscript.Echo "Description : "& iUSBDvc.Description
                Wscript.Echo "Manufacturer : "& iUSBDvc.Manufacturer
                Wscript.Echo "DeviceID : "& iUSBDvc.DeviceID
                Wscript.Echo "VID : "& sVID
                Wscript.Echo "PID : "& sPID
                Wscript.Echo String(10, "-")
    Next
    Set collUSBDvcs = Nothing

    End If
    Next

    Set collDvcs = Nothing
    Set oWMISrv = Nothing


    'Create instance of Altiris NSE component
    dim nse
    set nse = WScript.CreateObject ("Altiris.AeXNSEvent")

    ' Set the header data of the NSE
    ' Please don't modify this GUID
    nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
    nse.Priority = 1

    'Create Inventory data block. Here assumption is that the data class with below guid is already configured on server
    dim objDCInstance
    set objDCInstance = nse.AddDataClass ("USB_touch") '****Your Custom Data Class Name here

    dim objDataClass
    set objDataClass = nse.AddDataBlock (objDCInstance)

    For Each iUSBDvc in collUSBDvcs

    'Add a new row
    dim objDataRow
    set objDataRow = objDataClass.AddRow
    'Set columns
    objDataRow.SetField 0, iUSBDvc.Name
    objDataRow.SetField 0, iUSBDvc.Description
    objDataRow.SetField 0, iUSBDvc.Manufacturer
    objDataRow.SetField 0, iUSBDvc.DeviceID
    objDataRow.SetField 1, sVID
    objDataRow.SetField 3, sPID
    Next

    nse.SendQueued



  • 2.  RE: Custom inventory USB devices

    Posted 03-19-2020 12:30 PM
    Edited by Greg Smith 03-19-2020 12:31 PM
    Looking at your code below you create collUSBDvcs object, use it then Destroy it.
    When you use it you're sending output to the shell running the VBSCript.
    Set collUSBDvcs = oWMISrv.ExecQuery _
            ("Select * From Win32_PnPEntity Where DeviceID = '"& sDvcID &"'")
    For Each iUSBDvc in collUSBDvcs
                Wscript.Echo "Name : "& iUSBDvc.Name       
                Wscript.Echo "Description : "& iUSBDvc.Description
                Wscript.Echo "Manufacturer : "& iUSBDvc.Manufacturer
                Wscript.Echo "DeviceID : "& iUSBDvc.DeviceID
                Wscript.Echo "VID : "& sVID
                Wscript.Echo "PID : "& sPID
                Wscript.Echo String(10,"-")
    Next
    Set collUSBDvcs = Nothing​

    Later when you want to store that info into your inventory file you reuse the destroyed collUSBDvcs object

    For Each iUSBDvc in collUSBDvcs
    
    'Add a newrow
    dim objDataRow
    set objDataRow = objDataClass.AddRow
    'Set columns
    objDataRow.SetField 0, iUSBDvc.Name
    objDataRow.SetField 0, iUSBDvc.Description
    objDataRow.SetField 0, iUSBDvc.Manufacturer
    objDataRow.SetField 0, iUSBDvc.DeviceID
    objDataRow.SetField 1, sVID
    objDataRow.SetField 3, sPID
    Next

    Do you see what you need to do or do you need more help?