For over 15 years (I'm guessing) I've relied on many of Pierre excellent example programs to dig useful information out of windows. The only problem is when I had an interest in something that he wasn't interested in.
Once I discovered José Roca's WMIGENX program, there hasn't been very much I can't find. WMIGEN generates templates for WMI Classes. I put together a little program that might help you out.
'Created using Jose's WMI Templates Generator C:\PB\WMIGENX DBK
' ########################################################################################
' WMI Template
' Namespace = root\CIMV2
' WMI Class = Win32_PnPEntity
' ########################################################################################
#Compile Exe
#Dim All
#Include "WMI.INC" 'Since you are using FF, I know you are using Jose's include files
' ========================================================================================
' Retrieves the values of all of the properties of the Win32_PnPEntity class
' ========================================================================================
Function WMI_Win32_PnPEntity (Optional ByVal bstrComputer As WSTRING) As Long
Local hr As Long ' // HRESULT
Local pLocator As IWbemLocator ' // IWbemLocator interface reference
Local pService As IWbemServices ' // IWbemServices interface reference
Local pEnumClassObject As IEnumWbemClassObject ' // IEnumWbemClassObject collection reference
Local pClassObject As IWbemClassObject ' // IWbemClassObject interface reference
Local bstrResource As WSTRING ' // Path of the correct WMI namespace
Local bstrLanguage As WSTRING ' // Query language
Local bstrQuery As WSTRING ' // Query filter
Local uReturned As Dword ' // Number of returned references
' // Variants to store the property values
Local vAvailability As VARIANT ' // Unsigned 16-bit integer
Local vCaption As VARIANT ' // String
Local vClassGuid As VARIANT ' // String
Local vCompatibleID As VARIANT ' // Array - String
Local vConfigManagerErrorCode As VARIANT ' // Unsigned 32-bit integer
Local vConfigManagerUserConfig As VARIANT ' // Boolean value
Local vCreationClassName As VARIANT ' // String
Local vDescription As VARIANT ' // String
Local vDeviceID As VARIANT ' // String
Local vErrorCleared As VARIANT ' // Boolean value
Local vErrorDescription As VARIANT ' // String
Local vHardwareID As VARIANT ' // Array - String
Local vInstallDate As VARIANT ' // Date/time value
Local vLastErrorCode As VARIANT ' // Unsigned 32-bit integer
Local vManufacturer As VARIANT ' // String
Local vName As VARIANT ' // String
Local vPNPDeviceID As VARIANT ' // String
Local vPowerManagementCapabilities As VARIANT ' // Array - Unsigned 16-bit integer
Local vPowerManagementSupported As VARIANT ' // Boolean value
Local vService As VARIANT ' // String
Local vStatus As VARIANT ' // String
Local vStatusInfo As VARIANT ' // Unsigned 16-bit integer
Local vSystemCreationClassName As VARIANT ' // String
Local vSystemName As VARIANT ' // String
' // Sets the default security values for the process
hr = CoInitializeSecurity(ByVal %Null, -1, ByVal %Null, %Null, %RPC_C_AUTHN_LEVEL_DEFAULT, %RPC_C_IMP_LEVEL_IMPERSONATE, ByVal %Null, %EOAC_NONE, %Null)
If hr <> %S_OK Then Function = hr : Exit Function
' // Creates an instance of the IWbemLocator interface
pLocator = NEWCOM CLSID $CLSID_WbemLocator
If IsNothing(pLocator) Then Function = %E_FAIL: Exit Function
' // Connects with the specified machine
If Len(bstrComputer) And Right$(bstrComputer, 1) <> "\" Then bstrComputer +="\"
bstrResource = bstrComputer & "root\CIMV2"
hr = pLocator.ConnectServer(bstrResource, "", "", "", 0, "", Nothing, pService)
If hr <> %S_OK Then Function = hr : Exit Function
' // Sets security levels on the proxy
hr = CoSetProxyBlanket(pService, %RPC_C_AUTHN_WINNT, %RPC_C_AUTHZ_NONE, %Null, %RPC_C_AUTHN_LEVEL_CALL, %RPC_C_IMP_LEVEL_IMPERSONATE, %Null, %EOAC_NONE)
If hr <> %S_OK Then Function = hr : Exit Function
' // Executes the query
bstrLanguage = "WQL"
bstrQuery = "SELECT Name,DeviceID FROM Win32_PnPEntity " 'where DeviceID like '%VID_04D8%'"
hr = pService.ExecQuery(bstrLanguage, bstrQuery, %WBEM_FLAG_FORWARD_ONLY Or %WBEM_FLAG_RETURN_IMMEDIATELY, Nothing, pEnumClassObject)
hr = pService.ExecQuery(bstrLanguage, bstrQuery, %WBEM_FLAG_FORWARD_ONLY Or %WBEM_FLAG_RETURN_IMMEDIATELY, Nothing, pEnumClassObject)
' // Iterate through the collection of objects
Do
' // Retrieve a reference to the next object in the collection
hr = pEnumClassObject.Next(%WBEM_INFINITE, 1, pClassObject, uReturned)
If uReturned = 0 Then Exit Do
' // Retrieve the values of the properties
hr = pClassObject.Get("Availability", 0, vAvailability, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("Caption", 0, vCaption, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("ClassGuid", 0, vClassGuid, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("CompatibleID", 0, vCompatibleID, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("ConfigManagerErrorCode", 0, vConfigManagerErrorCode, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("ConfigManagerUserConfig", 0, vConfigManagerUserConfig, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("CreationClassName", 0, vCreationClassName, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("Description", 0, vDescription, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("DeviceID", 0, vDeviceID, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("ErrorCleared", 0, vErrorCleared, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("ErrorDescription", 0, vErrorDescription, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("HardwareID", 0, vHardwareID, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("InstallDate", 0, vInstallDate, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("LastErrorCode", 0, vLastErrorCode, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("Manufacturer", 0, vManufacturer, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("Name", 0, vName, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("PNPDeviceID", 0, vPNPDeviceID, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("PowerManagementCapabilities", 0, vPowerManagementCapabilities, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("PowerManagementSupported", 0, vPowerManagementSupported, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("Service", 0, vService, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("Status", 0, vStatus, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("StatusInfo", 0, vStatusInfo, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("SystemCreationClassName", 0, vSystemCreationClassName, ByVal %Null, ByVal %Null)
hr = pClassObject.Get("SystemName", 0, vSystemName, ByVal %Null, ByVal %Null)
Local sPorts As String
' If Left$(Variant$(vCaption),30)="Standard Serial over Bluetooth" Then sPorts += Variant$(vCaption) & $Cr
If InStr(Variant$(vName) & " " & Variant$(vDeviceID), "VID_04D8")>0 Then MsgBox _ ' <--------- Replace the 4 Hex digits with yours.
Variant$(vName) & " " & Variant$(vDeviceID)
' // Release the object
pClassObject = Nothing
Loop
' // Release the enumerator
pEnumClassObject = Nothing
' // Release the service
pService = Nothing
' // Release the locator
pLocator = Nothing
End Function
' ========================================================================================
' ========================================================================================
' Main
' ========================================================================================
Function PBMain
WMI_Win32_PnPEntity
End Function
' ========================================================================================
How I found my device:
In device manager, look at the Keyboards. I had two HID Keyboards. It wasn't hard to figure out which one I was looking for.
On the Details tab of the device properties, select Hardware Ids in the Property dropdown. I copied the VID (vendor ID) and pasted it in my code mentioned above.
Compile and run it. I get two msgboxes pop up when my device is plugged in. None when it is not.
You can cut most of the code out of that but I left it to let you see what it looks like right out of WMIGenX. The vName field won't be needed, but it lets you know the entry you are looking at is for a Keyboard.
I don't know if you are versed in SQL, but you can also leave off the "If" part of the Msgbox if you delete the " ' (DQ SQ) in the Select statement so that the Where statement is included in the query.
Let me know if you need further assistance because I didn't spend too much time putting this together for you. It's kind of sloppy.
David
BTW The PNPEntity was the best template for you because it deals with devices that can come and go. Somewhere in there we could find the name displayed in the screen capture you showed. Not sure that you need it, because you can detect if it's present with this code. I didn't go into how to use WMIGenX, it took a while to figure it out. Feel free to ask more about it if you need more info. I'll help where I can.