Something like this should work:
Set wmi = GetObject("winmgmts://./root/cimv2")
vid = "VID_0DF7"
pid = "PID_0620"
For Each d In wmi.ExecQuery("SELECT * FROM Win32_USBControllerDevice")
If InStr(d.Dependent, vid & "&" & pid) > 0 Then
WScript.Echo wmi.Get(d.Dependent).Description
End If
Next
If you want a notification when there's no device matching your criteria, you cannot implement an Else
branch inside the loop. A nested Else
would fire for each device that doesn't match the criteria, whereas you want a notification only if none of the devices match the criteria. Use a boolean value that you change to True
when you find a matching device:
found = False
For Each d In wmi.ExecQuery("SELECT * FROM Win32_USBControllerDevice")
If InStr(d.Dependent, vid & "&" & pid) > 0 Then
WScript.Echo wmi.Get(d.Dependent).Description
found = True
End If
Next
If Not found Then WScript.Echo "USB not found."