Enumerating CD Devices on Your System
Posted
by Aaron Young
on January 27th, 2004
Although this can now be done with the new FileSystemObject that comes with VB6 (and as an extra with VB5), this is how to get the drives through code when the target machine may not have the SSCRUN.DLL.
The code is quite simple and uses the GetDriveType and GetLogicalDriveStrings Windows API calls.
'
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
List1.AddItem "(CDRom) " & sDrive
End If
sDrives = mid$(sDrives, len(sDrive) + 2)
Wend
End Sub
'

Comments
More helpful for me
Posted by Legacy on 07/25/2003 12:00amOriginally posted by: Mohan
Reply