Given a drive letter, returns the type of disk present, if connected.
Module
Option Explicit
'API Calls
'Function GetDriveType
'lpRootPathName : string that specifies the root directory of the disk to return information about. If lpRootPathName is an empty string, the function uses the root of the current directory.
Public Declare Function GetDriveType Lib "kernel32.dll" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
'API Constants
Public Const DRIVE_UNKNOWN = 0
Public Const DRIVE_DOES_NOT_EXIST = 1
Public Const DRIVE_REMOVABLE = 2
Public Const DRIVE_FIXED = 3
Public Const DRIVE_REMOTE = 4
Public Const DRIVE_CDROM = 5
Public Const DRIVE_RAMDISK = 6
Usage
Private Sub Command1_Click()
'Get the type of the D:\ Drive
Select Case GetDriveType("D:\")
Case DRIVE_UNKNOWN
MsgBox "Type Unknown", vbExclamation
Case DRIVE_DOES_NOT_EXIST
MsgBox "Type Unknown", vbCritical
Case DRIVE_REMOVABLE
MsgBox "The disk can be removed from the drive", vbInformation
Case DRIVE_FIXED
MsgBox "The disk can not 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