查看: 244  |  回复: 0
VB6 利用API获得驱动器类型
楼主
发表于 2023年5月7日 13:11

新建From1(窗体),新建Command1(按钮CommandButton),代码:

Private Declare Function GetDriveType Lib "kernel32.dll" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Const DRIVE_UNKNOWN = 0
Private Const DRIVE_DOES_NOT_EXIST = 1
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6

Private Sub Command1_Click()
    Select Case GetDriveType("C:\")
        Case DRIVE_UNKNOWN
            MsgBox "Unknown drive type", vbExclamation
        Case DRIVE_DOES_NOT_EXIST
            MsgBox "Drive doesn't exist", vbCritical
        Case DRIVE_REMOVABLE
            MsgBox "The disk can be removed from the drive", vbInformation
        Case DRIVE_FIXED
            MsgBox "The disk cannot be removed from the drive", vbInformation
        Case DRIVE_REMOTE
            MsgBox "The drive is a remote (network) drive", vbInformation
        Case DRIVE_CDROM
            MsgBox "The drive is a CD-ROM drive", vbInformation
        Case DRIVE_RAMDISK
            MsgBox "The drive is a RAM disk", vbInformation
    End Select
End Sub


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2024 MaNongKu.com