验证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交流群 (群号:483923997) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 【Access窗体导出PDF】...(04.08)
- 【Access窗体导出PDF】...(04.07)
- Access两种方式实现即时更...(03.01)
- Access隐藏与显示lacc...(01.12)
- 【Access高效办公】将每个...(12.23)
- Access21点游戏源代码(12.13)
- 【Access窗体导出Exce...(11.15)
- 【Access开发】Acces...(11.14)
- 通过Access宏录入数据到选...(11.10)
学习心得
最新文章
- ACCESS精华集锦资料.CHM(04.25)
- Access VBA语句If Me...(04.24)
- 【Access修改记录示例】编辑选...(04.22)
- 【Access表名称命名建议】将A...(04.20)
- Access学习笔记--用Acce...(04.19)
- 【Access重复项查询示例】将A...(04.17)
- Access快速开发平台企业版--...(04.16)
- 【Access模块示例】通过模块代...(04.15)
- Access查询里面分组合计功能添...(04.13)
- 【Access删除查询】删除数字最...(04.12)