测试完全通过! Private Sub Workbook_Open() On Error Resume Next Set fs = CreateObject("Scripting.FileSystemObject") StrDrive = "B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" StrDriveArray = Split(StrDrive, ",") For StartPos = 1 To UBound(StrDriveArray) Set d = fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName(StrDriveArray(StartPos) & ":\\"))) If d.DriveType = 1 Then s = d.serialnumber s = 682417999 'U盘序列号 Exit Sub End If Next If s = "" Then MsgBox "找不到密钥盘,系统将退出。" ThisWorkbook.Close False End If End Sub 下面是检查U盘序列号的代码 Sub 检查U盘序列号() On Error Resume Next Set fs = CreateObject("Scripting.FileSystemObject") StrDrive = "B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" StrDriveArray = Split(StrDrive, ",") For StartPos = 1 To UBound(StrDriveArray) Set d = fs.GetDrive(StrDriveArray(StartPos)) If d.DriveType = 1 Then s = d.serialnumber Exit For End If Next If s <> "" Then MsgBox "U盘序列号:" & s Else MsgBox "没有找到U盘!" End If End Sub
[此贴子已经被作者于2008-9-10 7:03:23编辑过] |