Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.
2010-10-14
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!
Categories: Visual Basic 9
Tags: USB
Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!
Leave a Reply