|
发多一个检测移动盘的
Option Compare Database
Option Explicit
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, ByVal lPBuffer As String) As Long
Private Sub Command0_Click()
Dim rtn As String, a, b$(), i%, u As Boolean
Dim AllDrives As String
AllDrives = Space$(64) '设置缓冲
rtn = GetLogicalDriveStrings(Len(AllDrives), AllDrives) '调用函数得到包含所有驱动器的字符串
AllDrives = Left(AllDrives, rtn)
a = Split(Trim(AllDrives), Chr(0))
ReDim b(UBound(a))
u = False
For i = 0 To UBound(a) - 1
b(i) = GetDriveType(a(i))
If b(i) < 2 Or b(i) > 6 Then b(i) = 1
b(i) = Choose(Val(b(i)), "未知类型", "移动盘", "硬盘", "映射盘", "光驱", "内存盘")
If b(i) = "移动盘" Then u = True
Next
Text1 = ""
Text1 = IIf(u, "发现有移动盘!", "未发现移动盘!") & vbCrLf
For i = 0 To UBound(a) - 1
Text1 = Text1 & a(i) & "---" & b(i) & vbCrLf
Next
End Sub |
|