Solved

Parsing Device Manager with VB.Net

Posted on 2008-10-24
3
928 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Complex SQL statement in VB.NET 7 31
Groupbox Control ? 2 19
Access Schema 6 26
VB.net Code to make a TaskPane float in Excel Add-in 2 10
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 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