I am using Win32 API calls to get the information about the device classes and devices. Querying the device capabilities only seems to work for the PNP devices. The Non PNP devices are a different story.

This is the API call that gets the information for a given device:

Friend Sub New(ByVal hInfoSet As IntPtr, ByVal instanceInfo As DevInfoData)

Me.ptrDeviceInfoSet = hInfoSet
Me.devInfoData = instanceInfo
Me.lstProperties = New Dictionary(Of DevicePropertyID, Object)()

If NativeMethods.CM_Get_DevNode_Status(Me.difFlags, Me.dipProblem, Me.devInfoData.InstanceID, 0) = ConfigResult.Success Then
If (Me.difFlags And DeviceInstanceFlags.HAS_PROBLEM) = 0 Then
Me.dipProblem = DeviceInstanceProblem.NO_PROBLEM
End If
Else
Me.difFlags = DeviceInstanceFlags.HAS_PROBLEM
Me.dipProblem = DeviceInstanceProblem.NO_PROBLEM
End If

End Sub

This is the Visible property I created to determine if a given device is hidden or visible:

Public ReadOnly Property Visible() As Boolean

Get
If (Me.difFlags And DeviceInstanceFlags.NO_SHOW_IN_DM) = DeviceInstanceFlags.NO_SHOW_IN_DM Then
Me.blnVisible = False
Else
Me.blnVisible = True
End If

Return Me.blnVisible
End Get

End Property


Here's the code used to get the Device Classes and display them in the Treeview:


Public Sub Display(ByRef tvwTreeView As TreeView)

Dim tvwRootNode As New TreeNode
Dim tvwDeviceClassNode As New TreeNode

tvwTreeView.BeginUpdate()
tvwTreeView.Nodes.Clear()

tvwRootNode = New TreeNode
With tvwRootNode
.Name = "[Root}"
.Text = Environment.MachineName
End With
tvwTreeView.Nodes.Add(tvwRootNode)
For Each curDeviceClass As DeviceClass In DeviceClasses
If curDeviceClass.Present Then
For Each curDevice As Device In curDeviceClass.Devices
If curDevice.Visible Then
tvwDeviceClassNode = New TreeNode
With tvwDeviceClassNode
.ImageKey = curDeviceClass.Description
.SelectedImageKey = curDeviceClass.Description
.Text = curDeviceClass.Description
.Name = "[DeviceClass][" & curDeviceClass.Description & "]"
.Tag = "[DeviceClass][" & curDeviceClass.Description & "]"
End With
tvwRootNode.Nodes.Add(tvwDeviceClassNode)
Exit For
End If
Next
curDeviceClass.Devices.Display(curDeviceClass, tvwDeviceClassNode)
End If
Next
tvwTreeView.Sort()
tvwRootNode.Expand()
tvwTreeView.EndUpdate()

End Sub

Here's the code to display the devices for a given device class:

Public Sub Display(ByRef curDeviceClass As DeviceClass, ByRef tvwDeviceClassNode As TreeNode)

Dim tvwDeviceNode As New TreeNode

For Each curDevice As Device In curDeviceClass.Devices
If curDevice.Visible Then
tvwDeviceNode = New TreeNode
With tvwDeviceNode
.ImageKey = curDeviceClass.Description
.SelectedImageKey = curDeviceClass.Description
.Text = curDevice.FriendlyName
.Name = "[Device][" & curDevice.FriendlyName & "]"
.Tag = curDevice.FriendlyName
End With
tvwDeviceClassNode.Nodes.Add(tvwDeviceNode)
End If
Next

End Sub


Let me know if you need to see more of the code. I'd rather not post the whole project here on the site but I realize that you might need to see the whole project in working order to assist me.