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
2010-09-19 03:00:47
Would you please show me how to?
Phoenix
2010-09-19 03:02:08
I edited my post to include some code.
Dennis Delimarsky
2010-09-19 03:08:23
I tried your code, but its showing error: Type 'managementObjectSearcher' is not definedType 'managementObject' is not defined
Phoenix
2010-09-19 04:36:09
Did you add Imports System.Management to the class header?
Dennis Delimarsky
2010-09-19 05:24:29
I seriously doubt the OP wants this. The controller properties are always the same on the same machine.
Hans Passant
2010-09-19 12:50:54
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
2010-09-19 16:39:59