验证U盘的SerialNumber(可以用于登陆,权限控制等操作)
时 间:2017-04-27 09:50:52
作 者:易勋 ID:35404 城市:上海
摘 要:SerialNumber,返回十进制序列号,用于唯一标识一个磁盘卷。
正 文:
函 数:
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Public Function CheckDrive() As Boolean
Dim StrDrive As String
Dim DriveID As String
Dim i As Integer
Dim m As Long
Dim myDrive As Object
CheckDrive = False
StrDrive = String(100, Chr$(0)) '初始化盘符串
m = GetLogicalDriveStrings(100, StrDrive) '返回盘符串
For i = 1 To 100 Step 4 '注意这里是4
DriveID = Mid(StrDrive, i, 3) '枚举盘符
If DriveID = Chr$(0) & Chr(0) & Chr(0) Then Exit For '没有盘符,即时退出循环
If GetDriveType(DriveID) = 2 Then
Set myDrive = CreateObject("Scripting.FileSystemObject").GetDrive(DriveID)
If Not myDrive.IsReady Then Exit Function '如果磁盘不可用,就终止函数
If myDrive.VolumeName = "RECOVERY" And myDrive.SerialNumber = "-1634556752" Then '“-1634556752”是我的U盘系列码,“RECOVERY”是我的U盘卷标,
CheckDrive = True
End If
End If
Next i
End Function
用 法:
If CheckDrive Then MsgBox "验证成功!" Else MsgBox "验证失败!" End If
预设U盘的SerialNumber和VolumeName,插入U盘后调用函数CheckDrive,返回Ture或者False。
参考文章:
通过FileSystemObject获取驱动器信息[Access软件网]
http://www.accessoft.com/article-show.asp?id=11459
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 用Access连续窗体制作的树...(11.03)
- 【Access高效办公】上一年...(10.30)
- Access制作的RGB转CM...(09.22)
- Access制作的RGB调色板...(09.15)
- Access制作的快速车牌输入...(09.13)
- 【Access高效办公】统计当...(06.30)
- 【Access高效办公】用复选...(06.24)
- 根据变化的日期来自动编号的示例...(06.20)
- 【Access高效办公】按日期...(06.12)
学习心得
最新文章
- SqlServer默认当前时间用什...(11.28)
- 【Access日期时间区间段查询示...(11.19)
- Microsoft Access不...(11.07)
- 用Access连续窗体制作的树菜单...(11.03)
- 【Access高效办公】上一年度累...(10.30)
- Access做的一个《中华经典论语...(10.25)
- Access快速开发平台--加载事...(10.20)
- 【Access有效性规则示例】两种...(10.10)
- EXCEL表格扫描枪数据录入智能处...(10.09)
- Access快速开发平台--多行文...(09.28)


.gif)
