【发布时间】:2014-01-17 16:36:14
【问题描述】:
首先,我要感谢您抽出时间阅读我的帖子。 我需要一个 Visual basic 或 VBSCript 代码来检测是否插入了特定的 USB。 我有这些信息:
VID_0DF7 PID_0620
我的代码不想工作 :( 我不知道如何让它只读取特定的 VID 和 Pid :( 请不要仅仅因为我不知道该怎么做而对我的帖子竖起大拇指。 我在互联网上找到了很多例子,但实际上是为了告诉所有插入设备的 PID 和 VID 是什么......所以......我不需要它们......
我的代码:
strComputer = "."
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 & "'")
For Each objUSBDevice in colUSBDevices
Wscript.Echo objUSBDevice.Description
Next
Next
谢谢!
【问题讨论】: