Reading the serial number of USB storage device in Vb

萝らか妹 提交于 2019-12-09 03:51:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!