[原创]一个取系统驱动器名称的类模块

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

'中文注释成乱码了。可以删掉。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值