Keep track on USB devices

Microsoft provides a library for talking to USB devices as part of the .NET Framework. This is just one thing you can do with the versatile System.Management namespace. If you want to keep track on the units that are connected or removed from a computer, you can use this library for regular checks. This code, lists the name and ID of all connected devises. The code requires a reference to the System.Management namespace:

Using Mn As New System.Management.ManagementClass("Win32_USBHub")
   Using Devs As System.Management.ManagementObjectCollection _
      = Mn.GetInstances()
      For Each Dev As System.Management.ManagementObject In Devs
         Console.WriteLine(Dev.GetPropertyValue("Name").ToString())
         Console.WriteLine(Dev.GetPropertyValue("DeviceID").ToString())
      Next
   End Using
End Using

My code is written in an console application. The result will be a list of connected USB device names and their unique ID. Have fun!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll:

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Comments

Important information: If you have not commented before, your comment will be reviewed before it is published. This means that you will not see it immediately, but I have received it. This is not because I want to filter comments, but because I want to prevent spam and advertising.

Leave a Reply

Your email address will not be published. Required fields are marked *