?
Solved

Parsing Device Manager with VB.Net

Posted on 2008-10-24
3
Medium Priority
?
939 Views
Last Modified: 2012-05-05
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
Comment
Question by:ali678
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1000 total points
ID: 22803169
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 19 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question