question

kavehrahimi-5744 avatar image
0 Votes"
kavehrahimi-5744 asked XingyuZhao-MSFT commented

Find serial number of USB device

Hi ,I want to find the serial number of CH341A device. How can I do that?
Please help
Thanks

dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

XingyuZhao-MSFT avatar image
0 Votes"
XingyuZhao-MSFT answered XingyuZhao-MSFT commented

Hi @kavehrahimi-5744 ,
Add reference to 'System.Management', then try the code like:

         Dim theSearcher As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE InterfaceType='USB'")
    
         For Each currentObject As ManagementObject In theSearcher.Get()
             Dim theSerialNumberObjectQuery As ManagementObject = New ManagementObject()
             theSerialNumberObjectQuery.Path = "Win32_PhysicalMedia.Tag='" & currentObject("DeviceID") & "'"
             MessageBox.Show(theSerialNumberObjectQuery("SerialNumber").ToString())
         Next

Hope it could be helpful.
Best Regards,
Xingyu Zhao


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

May I use 'reported device ids hash' instead of serial number in device manager?

0 Votes 0 ·

Hi @kavehrahimi-5744 ,
Not sure you can get 'reported device ids hash', do you consider getting the 'PNPDeviceID' of USB?
Here's the code you can refer to.

         Dim theSearcher As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE InterfaceType='USB'")
    
         For Each currentObject As ManagementObject In theSearcher.Get()
             Console.WriteLine($"{"PNPDeviceID"}-{currentObject.Properties("PNPDeviceID").Value}")
         Next
0 Votes 0 ·