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
Private Const DRIVE_CDROM = 5
Private Const DRIVE_FIXED = 3
Private Const DRIVE_RAMDISK = 6
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_REMOVABLE = 2
'Value Meaning
'------------------------------------------------------------
'DRIVE_UNKNOWN The drive type cannot be determined.
'DRIVE_NO_ROOT_DIR The root directory does not exist.
'DRIVE_REMOVABLE The disk can be removed from the drive.
'DRIVE_FIXED The disk cannot be removed from the drive.
'DRIVE_REMOTE The drive is a remote (network) drive.
'DRIVE_CDROM The drive is a CD-ROM drive.
'DRIVE_RAMDISK The drive is a RAM disk.
'-------------------------------------------------------------
Private Drv(26) As String
Private DrvType(26) As Integer
'±£³ÖÊôÐÔÖµµÄ¾Ö²¿±äÁ¿
Private mvarDriveCount As Integer '¾Ö²¿¸´ÖÆ
Public Function GType(ByVal N As Integer) As Integer
GType = DrvType(N)
End Function
Public Function GDrvName(ByVal N As Integer) As String
GDrvName = Drv(N)
End Function
Property Let DriveCount(ByVal vData As Integer)
'ÏòÊôÐÔÖ¸ÅÉֵʱʹÓã¬Î»ÓÚ¸³ÖµÓï¾äµÄ×ó±ß¡£
'Syntax: X.DriveCount = 5
mvarDriveCount = vData
End Property
Property Get DriveCount() As Integer
'¼ìË÷ÊôÐÔֵʱʹÓã¬Î»ÓÚ¸³ÖµÓï¾äµÄÓұߡ£
'Syntax: Debug.Print X.DriveCount
DriveCount = mvarDriveCount
End Property
'With this class you can get the systme disk Drive Name and its type
Private Sub Class_Initialize()
Dim PathStr As String * 200
Dim DriveStr As String
mvarDriveCount = 0
If GetLogicalDriveStrings(200, PathStr) <> 0 Then
DriveStr = Mid(PathStr, 1, InStr(1, PathStr, Chr$(0) & Chr$(0)))
L = Len(DriveStr)
For I = 1 To L Step 4
mvarDriveCount = mvarDriveCount + 1
Drv(mvarDriveCount) = Mid(DriveStr, I, 3)
DrvType(mvarDriveCount) = GetDriveType(Drv(mvarDriveCount))
Next I
End If
End Sub
'中文注释成乱码了。可以删掉。