views:

33

answers:

1

Can anyone tell me how to get USB serial number(Hardware ID) using VB.net?

A: 

You should use WMI for this, specifically querying the Win32_USBController Class. The property you want to get is DeviceID.'

A sample WMI call in the context of a console application might look like this:

Dim mos As New ManagementObjectSearcher("SELECT * FROM Win32_UsbController")

For Each mo As ManagementObject In mos.Get()
    Console.WriteLine(mo.Properties.Item("DeviceID").Value)
Next

Console.ReadLine()

You would need to add references to System.Management and System.Management.Instrumentation to use ManagementObjectSearcher and ManagementObject.

Dennis Delimarsky
Would you please show me how to?
Phoenix
I edited my post to include some code.
Dennis Delimarsky
I tried your code, but its showing error: Type 'managementObjectSearcher' is not definedType 'managementObject' is not defined
Phoenix
Did you add Imports System.Management to the class header?
Dennis Delimarsky
I seriously doubt the OP wants this. The controller properties are always the same on the same machine.
Hans Passant
The problem is - to go deeper to get to the manufacturer's ID the OP would either need an SDK from that manufacturer or develop a lower-level library that could do that. WMI goes as far as providing the IDs outlined in the post.
Dennis Delimarsky