问题
Is it possible to read the serial number of a USB drive using VB.
回答1:
this will give you the info on your drives in .net, including usb devices Just import these
Imports Scripting Imports System.IO
Private Class USBsn
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim driveNames As New List(Of String)
For Each drive As DriveInfo In My.Computer.FileSystem.Drives
Try
Dim fso As Scripting.FileSystemObject
Dim oDrive As Drive
fso = CreateObject("Scripting.FileSystemObject")
oDrive = fso.GetDrive(drive.Name)
ListBox1.Items.Add(drive.Name & " " & oDrive.SerialNumber)
Catch ex As Exception
End Try
Next
End Sub
End Class
回答2:
Google found these tutorials:
visual basic (for hdd serial, but it seems it works for a usb drive too):
http://www.codeproject.com/KB/cs/hard_disk_serialno.aspx
powershell and vbasic:
http://blogs.msdn.com/powershell/archive/2007/02/24/displaying-usb-devices-using-wmi.aspx
vbasic:
http://www.myitforum.com/forums/m_147418/mpage_1/key_/tm.htm
回答3:
It's in the registry, HKLM\System\CCS\Enum\USB\VID_XXXX&PID_YYYY\<serial>.
(Vendor and Product ID will vary too, as serial numbers are only unique for a single product.)
来源:https://stackoverflow.com/questions/1158427/reading-the-serial-number-of-usb-storage-device-in-vb