Public Declare Function GetLogicalDriveStrings Lib "kernel32" _
Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
Public Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long
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
===========================================================
Dim r As Long
Dim allDrives As String
Dim currDrive As String
Dim drvType As String
'get the list of all available drives
allDrives = GetDriveString()
'separate the drive strings and retrieve the drive type
Do Until allDrives = Chr$(0)
'strip off one drive from the string allDrives
currDrive = StripNulls(allDrives)
'get the drive type
drvType = rgbDrvType(currDrive)
Print " " & currDrive & vbTab & drvType
Loop
End Sub
Private Function rgbDrvType(RootPathName) As String
'Passed is the drive to check.
'Returned is the type of drive.
Select Case GetDriveType(RootPathName)
Case 0: rgbDrvType = "The drive type cannot be determined"
Case 1: rgbDrvType = "The root directory does not exist"
Case DRIVE_REMOVABLE:
Select Case Left$(RootPathName, 1)
Case "a", "b": rgbDrvType = "Floppy drive"
Case Else: rgbDrvType = "Removable drive"
End Select
Case DRIVE_FIXED: rgbDrvType = "Hard drive; can not be removed"
Case DRIVE_REMOTE: rgbDrvType = "Remote (network) drive"
Case DRIVE_CDROM: rgbDrvType = "CD-ROM drive"
Case DRIVE_RAMDISK: rgbDrvType = "RAM disk"
End Select
End Function
Private Function GetDriveString() As String
'returns string of available
'drives each separated by a null
Dim sBuffer As String
'possible 26 drives, three characters each, plus trailing null
sBuffer = Space$(26 * 4)
If GetLogicalDriveStrings(Len(sBuffer), sBuffer) Then
'do not trim off trailing null!
GetDriveString = Trim$(sBuffer)
End If
End Function
Private Function StripNulls(startstr As String) As String
'Take a string separated by chr$(0)
'and split off 1 item, shortening the
'string so next item is ready for removal.
Dim pos As Long