文件名称:USB序列号的获取例程
文件大小:5KB
文件格式:RAR
更新时间:2016-04-25 12:22:25
VB USB 序列号
很简单的方法获得USB的序列号 Option Explicit Private Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Integer, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long Private Const DRIVE_CDROM = 5 '返回USB路径 Private Function GetUSBPath() As String Dim I As Integer On Error Resume Next For I = 97 To 122 Step 1 If GetDriveType(Chr(I) & ":\") = DRIVE_CDROM Then GetUSBPath = Chr(I + 1) & ":\" End If Next I End Function '返回序列号 Private Function GetPathInfo(PathStr As String) As String Dim MySerial As Long, MyLong As Long, MyType, MyStr MyStr = String$(255, Chr$(0)) MyType = String$(255, Chr$(0)) MyLong = GetVolumeInformation(PathStr, MyStr, Len(MyStr), MySerial, 0, 0, MyType, Len(MyType)) GetPathInfo = MySerial End Function Private Sub Command1_Click() Text1.Text = GetUSBPath MsgBox IIf(GetPathInfo(GetUSBPath) = 0, "USB没有连接磁盘", GetPathInfo(GetUSBPath)) End Sub
【文件预览】:
工程1.exe
Form1.frm
工程1.vbp
工程1.vbw