anyone got any code/API calls for getting a list of a computer's CD drives? thank u for any code.
Printable View
anyone got any code/API calls for getting a list of a computer's CD drives? thank u for any code.
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:Example Usage:VB Code:
Option Explicit 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 Public Enum enmDriveType ALLDRIVES = 0 CDROM = 5 FIXED = 3 RAMDISK = 6 REMOTE = 4 REMOVABLE = 2 End Enum Public Function GetDrives(Optional ByVal DriveType As enmDriveType = ALLDRIVES) As Variant Dim sDrives As String Dim sDrive As String Dim sDriveList() As String Dim lDriveCount As Long Dim eType As enmDriveType sDrives = Space(255) ' Extract a List of Logical Drive Letters sDrives = Left$(sDrives, GetLogicalDriveStrings(255, sDrives)) ' Step through each Drive Letter Do While Len(sDrives) sDrive = UCase$(Left$(sDrives, 3)) sDrives = Mid$(sDrives, 5) ' Get the Type of this Drive eType = GetDriveType(sDrive) ' If it matches what we want, or we want all drives, ' Add it to the Array of Drives to Return If eType = DriveType Or DriveType = ALLDRIVES Then ReDim Preserve sDriveList(lDriveCount) sDriveList(lDriveCount) = sDrive lDriveCount = lDriveCount + 1 End If Loop ' If Drives were found, return the Array, ' Otherwise return an empty array If lDriveCount > 0 Then GetDrives = sDriveList Else GetDrives = Array() End If End FunctionVB Code:
Private Sub Form_Load() Dim vDrives As Variant Dim lDrive As Long ' Get a List of CDROM Drive Letters Only vDrives = GetDrives(CDROM) For lDrive = 0 To UBound(vDrives) List1.AddItem vDrives(lDrive) Next End Sub
thank u very much