strComputer = "."
Set fso = CreateObject("Scripting.FileSystemObject")
Set dd= fso.CreateTextFile("USB设备列表文件.txt")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
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 & "'")
aa=InStr(strDeviceName,"PID_")
bb=InStr(strDeviceName,"MI_")
cc=Left(strDeviceName,3)
if aa>1 and bb<1 and cc="USB" then
dd.write (strDeviceName&vbCrLf)
else
end if
Next
msgbox "查询完毕!",64,"smny"