try this sample from Kaverin,
VB Code:
'Author Kaverin 'in a module 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 Function GetCDDriveLetter() As String Dim strBuffer As String Dim astrDrives As Variant Dim lngLength As Long Dim i As Integer Const CDROM As Long = 5 'make buffer strBuffer = Space$(256) 'get all drive strings lngLength = GetLogicalDriveStrings(Len(strBuffer), strBuffer) 'chop off the unnecessary part strBuffer = Left$(strBuffer, lngLength) 'break up the string into the drives astrDrives = Split(strBuffer, vbNullChar) For i = 0 To UBound(astrDrives) If GetDriveType(astrDrives(i)) = CDROM Then 'if the drive is a cd rom, we're done, so return the letter GetCDDriveLetter = Left$(astrDrives(i), 1) Exit Function End If Next i 'if you get to this point, there is no cd rom, so return "" GetCDDriveLetter = "" End Function




Reply With Quote