這看起來有用:How Can I Determine Which USB Devices are Connected to a Computer?
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
樣本輸出(應該是一棵樹):
USB Root Hub
Microsoft USB IntelliMouse Web
Microsoft USB IntelliMouse Web
USB Mass Storage Device
Disk drive
Generic volume
USB Root Hub
USB Root Hub
我希望不是所有的USB存儲自己描述爲 「USB大容量存儲設備」。如果有,請檢查卷名稱或autorun.inf(如果有)。
微軟是USB的發明者之一,它不太可能需要this Linux info,但它可能會搜索像「Pendrive」和「Flash Drive」這樣的搜索術語。
您是否嘗試過WMI? Win32_LogicalDrive和Win32_PhysicalMedia看起來很有前途。在編寫任何代碼之前先使用WMI Code Creator實用程序。 – 2012-02-12 14:00:56
不,我以前只有WMI頭疼過。我儘量避免它。 WMI會在Windows服務中工作嗎? – wpfwannabe 2012-02-12 14:23:22
嗨,你有沒有得到這個問題的答案?我也需要這樣做 – 2012-08-12 21:14:58