Solved

Parsing Device Manager with VB.Net

Posted on 2008-10-24
3
918 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
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now