Tramite API
private Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" (byval nDrive as string) as Long
private Declare Function GetLogicalDriveStrings Lib "kernel32" _
Alias "GetLogicalDriveStringsA" (byval nBufferLength as Long, _
byval lpBuffer as string) as Long
private Const DRIVE_CDROM = 5
private Sub ListCDROMs()
Dim sDrives as string
Dim sDrive as string
sDrives = Space(255)
sDrives = Left$(sDrives, GetLogicalDriveStrings(255, byval sDrives))
While InStr(sDrives, "\")
sDrive = Left$(sDrives, InStr(sDrives, "\"))
If GetDriveType(sDrive) = DRIVE_CDROM then
Debug.Print "(CDRom) " & sDrive
End If
sDrives = mid$(sDrives, len(sDrive) + 2)
Wend
End Sub
Tramite FileSystemObject
Dim fso As New Scripting.FileSystemObject
Dim drv As Drive
For Each drv In fso.Drives
If drv.DriveType = CDRom Then
CDPath = drv.Path
Exit For
End If
Next drv
Set drv = Nothing
Set fso = Nothing
Per sapere se un cd è o non è nel lettore beh windows passa il messaggio WM_DEVICECHANGE quando avviene qualcosa, quindi dovresti intercettarlo e gestirlo (subclassing).
Guarda questo esempio.
http://www.allapi.net/php/redirect/r...ownload&id=368