rss

Retired Scripts: USB Info HTA

This script displays USB device info available in WMI. I really didn't need this script -- I think it was used about five times -- but, writing HTAs is so much fun they almost make us script kiddie Sys Admins feel legit.

image

showusbinfo.hta

<!-- See info block in script section... -->
<head>
    <title>USB Hardware Poll</title>
    <hta:application applicationname="USB HW Test" caption="yes" sysmenu="yes" border="dialog"
        scroll="no" singleinstance="yes" maximizebutton="no" minimizebutton="no" selection="no"
        windowstate="normal">
</head>
 
<script language="VBScript">
 
'******************************************************************************
'* USB info HTA Script
'* Modified: 9:01 AM 06/07/28  -  J. Bilinski
'******************************************************************************
 
 
On Error Resume Next
strComputer = "."
window.resizeTo 640,480
Set objWMIService = GetObject(_
    "winmgmts:\\" & strComputer & "\root\cimv2")
 
strOutCache = ""
 
'---Begin User Variable---
 
 
'---End User Variables---
 
Sub Window_onLoad
On Error Resume Next
'DumpUSBHub()
DumpUSBCrtl()
End Sub
 
Sub OutLog(strOutTXT)
strOutCache = strOutCache & strOutTXT & vbCrLf 
OutputArea.value = strOutCache
strOutTXT = ""
End Sub
 
Sub DumpUSBHub()
Set colItems = objWMIService.ExecQuery( _
    "Select * from Win32_USBHub")
For Each objItem in colItems
    OutLog("Device ID: " & objItem.DeviceID)
    OutLog("PNP Device ID: " & objItem.PNPDeviceID)
    OutLog("Description: " & objItem.Description)
    OutLog("Description: " & objItem.Description)
Next
End Sub
 
Sub DumpUSBCrtl()
Set colDevices = objWMIService.ExecQuery _ 
   ("Select * From Win32_USBControllerDevice") 
 
For Each objDevice in colDevices 
   strDeviceName = objDevice.Dependent 
   strQuotes = Chr(34) 
   strDeviceName = Replace(strDeviceName, strQuotes, "") 
   arrDeviceNames = Split(strDeviceName, "=") 
   strDeviceName = arrDeviceNames(1) 
   Set colUSBDevices = objWMIService.ExecQuery _ 
       ("Select * From Win32_PnPEntity Where DeviceID = '" & strDeviceName & "'") 
   For Each objUSBDevice in colUSBDevices 
       OutLog(objUSBDevice.Description)
       OutLog(objUSBDevice.PnPDeviceID)' Changed from Description to PnPDeviceID 
   Next    
Next 
End Sub
 
 
Sub ExitScript
self.close()
End Sub
 
Sub ErrorHandler(strText)
 
  Dim strError
  strError = " ERROR:0x" & Hex(Err.Number) & "-" & Err.Description &" WARNING: "& strText 
  boolError = TRUE
  boolStageError = TRUE
  OutLog(strError)
 
End Sub
 
</script>
 
<body style="font: 10 pt arial; color: white; filter: progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#000000', EndColorStr='#333333')">
USB Devices
        <hr />
        Script Output:<br>
        <textarea id="OutputArea" cols="20" style="width: 100%; color: white; height: 400px;
            background-color: transparent; font-family: 'Lucida Console'; font-size: 8pt;"
            name="OutputArea" readonly="readOnly" lang="en">
</textarea>
 
</body>

 

More Scriptdump...

Bookmark


TrackBack URL: http://bilinski.org/trackback.ashx?id=28


Leave a Comment

 

 (optional/private)

(optional/public)