• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 955
  • Last Modified:

Parsing Device Manager with VB.Net

I cant seem to get the devices starting with A in the Universal Serial Bus Controller.

i've tired Win32_USBHUB and alot more, but i always get an error , how do i get to the locate with the usb devices?

Thanks.


      Public Sub Detect2()
   
              Me.ListBox1.Items.Clear()
   
       
   
              Dim searcher As New ManagementObjectSearcher("SELECT * FROM  Win32_PnPEntity")
   
              For Each PnPDevice As ManagementObject In searcher.Get()
   
                  If Not PnPDevice("Service") Is Nothing Then
   
                      If PnPDevice("Service").ToString().StartsWith("A") Then
   
                         Me.ListBox1.Items.Add(PnPDevice("Name").ToString())
   
                      End If
 
                  End If
 
              Next PnPDevice
 
          End Sub
0
ali678
Asked:
ali678
1 Solution
 
Bob LearnedCommented:
Are you looking for a list of USB devices?


' Add the System.Management.dll reference to the project.
Imports System.Management
Imports System.Collections.Generic
 
Public Class Win32_UsbDevice
    Public Name As String
    Public DeviceID As String
    Public Status As String
 
    Public Shared Function GetList() As List(Of Win32_UsbDevice)
 
        Dim query As String = "Select * From WIN32_USBControllerDevice"
 
        Dim searcher As New ManagementObjectSearcher(query)
 
        Dim results As ManagementObjectCollection = searcher.Get()
 
        Dim list As New List(Of Win32_UsbDevice)
 
        Dim index As Integer = 0
 
        For Each entryCurrent As ManagementObject In results
 
            Dim device As New Win32_UsbDevice
 
            device.Name = entryCurrent("Name")
            device.DeviceID = entryCurrent("DeviceID")
            device.Status = entryCurrent("Status")
 
            list.Add(device)
 
            index += 1
 
        Next entryCurrent
 
        Return list
 
    End Function
 
    Public Overrides Function ToString() As String
        Return String.Format("Name={0}, DeviceID={1}, Status={2}", Name, DeviceID, Status)
    End Function
 
 
End Class

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now