Results 1 to 3 of 3

Thread: enum CD drives

  1. #1
    TheSarlacc
    Guest

    enum CD drives

    anyone got any code/API calls for getting a list of a computer's CD drives? thank u for any code.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Here's a wrapper I wrote around a couple of Win32 API's that get Drive information, you can use this to return ALL Drive letters or only those of a certain type of drive, i.e. CDROM:

    In a Standard Module:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    4. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    5.  
    6. Public Enum enmDriveType
    7.     ALLDRIVES = 0
    8.     CDROM = 5
    9.     FIXED = 3
    10.     RAMDISK = 6
    11.     REMOTE = 4
    12.     REMOVABLE = 2
    13. End Enum
    14.  
    15. Public Function GetDrives(Optional ByVal DriveType As enmDriveType = ALLDRIVES) As Variant
    16.     Dim sDrives As String
    17.     Dim sDrive As String
    18.     Dim sDriveList() As String
    19.     Dim lDriveCount As Long
    20.     Dim eType As enmDriveType
    21.    
    22.     sDrives = Space(255)
    23.     ' Extract a List of Logical Drive Letters
    24.     sDrives = Left$(sDrives, GetLogicalDriveStrings(255, sDrives))
    25.    
    26.     ' Step through each Drive Letter
    27.     Do While Len(sDrives)
    28.         sDrive = UCase$(Left$(sDrives, 3))
    29.         sDrives = Mid$(sDrives, 5)
    30.         ' Get the Type of this Drive
    31.         eType = GetDriveType(sDrive)
    32.         ' If it matches what we want, or we want all drives,
    33.         ' Add it to the Array of Drives to Return
    34.         If eType = DriveType Or DriveType = ALLDRIVES Then
    35.             ReDim Preserve sDriveList(lDriveCount)
    36.             sDriveList(lDriveCount) = sDrive
    37.             lDriveCount = lDriveCount + 1
    38.         End If
    39.     Loop
    40.    
    41.     ' If Drives were found, return the Array,
    42.     ' Otherwise return an empty array
    43.     If lDriveCount > 0 Then
    44.         GetDrives = sDriveList
    45.     Else
    46.         GetDrives = Array()
    47.     End If
    48. End Function
    Example Usage:
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim vDrives As Variant
    3.     Dim lDrive As Long
    4.    
    5.     ' Get a List of CDROM Drive Letters Only
    6.     vDrives = GetDrives(CDROM)
    7.     For lDrive = 0 To UBound(vDrives)
    8.         List1.AddItem vDrives(lDrive)
    9.     Next
    10. End Sub

  3. #3
    TheSarlacc
    Guest
    thank u very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width