Results 1 to 4 of 4

Thread: Detecting CD drive..

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091

    Detecting CD drive..

    Hi,

    I'm creating an application that will need to browse a CD-Rom in the CD drive to get certain files.

    My question is, how do you detect the user's CD drive letter? Also, what if the user has moer than 1 cd drive, such as a cd and a cd-writer? How would I know which one to browse?

    Any help and example code would be appreciated..

    Dan

    Visual Studio 2010

  2. #2
    PowerPoster eiSecure's Avatar
    Join Date
    Jul 2000
    Location
    Texas
    Posts
    2,209
    I'm creating an application that will need to browse a CD-Rom in the CD drive to get certain files.
    The common dialog control will work with that, wouldn't it?

  3. #3
    Megatron
    Guest
    Use the GetDriveType API.
    VB Code:
    1. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    2. Const DRIVE_CDROM = 5
    3.  
    4. 'Returns an array with all the CD Drive's
    5. Function GetCDDrives() As Variant
    6.     Dim vDrives() As Variant
    7.     Dim iCount As String
    8.     iCount = 0
    9.    
    10.     For I = Asc("A") To Asc("Z")
    11.         If GetDriveType(Chr$(I) & ":") = DRIVE_CDROM Then
    12.             ReDim vDrives(iCount)
    13.             vDrives(iCount) = Chr$(I)
    14.         End If
    15.     Next I
    16.     GetCDDrives = vDrives
    17. End Function
    Usage:
    VB Code:
    1. v = GetCDDrives
    2.  
    3. For I = LBound(v) To UBound(v)
    4.     Print v(I)
    5. Next I

  4. #4
    New Member
    Join Date
    Jul 2001
    Location
    Kalamazoo, Michigan
    Posts
    13

    How to detect CD

    got your answer:


    Private Declare Function GetDriveType Lib "kernel32" Alias _
    "GetDriveTypeA" (ByVal nDrive As String) As Long
    Private Const DRIVE_CDROM = 5

    Public Function GetCDROMDriveLetter() As String
    Dim DriveChar As Byte
    'Dim tmpDrive As String

    GetCDROMDriveLetter = "Unknown"

    On Error GoTo ErrorHandler

    For DriveChar = 0 To 25
    tmpDrive = Chr(65 + DriveChar) & ":\"
    If (GetDriveType(tmpDrive) = DRIVE_CDROM) Then
    GetCDROMDriveLetter = tmpDrive
    varDrive = tmpDrive
    Exit For
    End If
    Next DriveChar

    'varDrive = tmpDrive
    ErrorHandler:
    Exit Function

    End Function

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