Results 1 to 7 of 7

Thread: Find Your CD Drive

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2001
    Location
    Hyderabad,India
    Posts
    37
    hai Friends,
    is there any way of finding the Cd drive letter like e or d or ...



    srikanth
    A.Srikanth
    Application Engineer

  2. #2
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  3. #3
    ~~~
    Guest
    The link gets me a 404 error. I searched for the article but that link was also not working. Maybe I should inform VB Square...

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'get the first CD Rom drive letter and use it as default 
    
    Option Explicit 
    
    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 
    
    Const DRIVE_CDROM As Long = 5 
    
    Private Sub cmdGo_Click() 
    Dim strDriveLetter As String 
    
    ' Call the GetFirstCdRomDriveLetter() and store the 
    ' return value in strDriveLetter. 
    strDriveLetter = GetFirstCdRomDriveLetter() 
    
    ' Display the drive letter in a message box. 
    MsgBox strDriveLetter 
    
    End Sub 
    
    Function GetFirstCdRomDriveLetter() As String 
    ' Declare variables. 
    Dim lDriveType As Long 
    Dim strDrive As String 
    Dim lStart As Long: lStart = 1 
    
    ' Create a string to hold the logical drives. 
    Dim strDrives As String 
    strDrives = Space(150) 
    
    ' Get the logial drives on the system. 
    ' If the function fails it returns zero. 
    Dim lRetVal As Long 
    lRetVal = GetLogicalDriveStrings(150, strDrives) 
    ' Check to see if GetLogicalDriveStrings() worked. 
    If lRetVal = 0 Then 
    ' Get GetLogicalDriveStrings() failed. 
    GetFirstCdRomDriveLetter = vbNullString 
    Exit Function 
    End If 
    ' Get the string that represents the first drive. 
    strDrive = Mid(strDrives, lStart, 3) 
    
    Do 
    ' Test the first drive. 
    lDriveType = GetDriveType(strDrive) 
    ' Check if the drive type is a CD-ROM. 
    If lDriveType = DRIVE_CDROM Then 
    
    ' Found the first CD-ROM drive on the system. 
    GetFirstCdRomDriveLetter = strDrive 
    Exit Function 
    End If 
    ' Increment lStart to next drive in the string. 
    lStart = lStart + 4 
    ' Get the string that represents the first drive. 
    strDrive = Mid(strDrives, lStart, 3) 
    Loop While (Mid(strDrives, lStart, 1) <> vbNullChar) 
    
    End Function
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Another way (this will put all the CD-Rom drives in a listbox, and without using Mid, which AFAIK is a little bit faster):


    Code:
    Private Declare Function GetLogicalDrives Lib "kernel32" () As Long
    Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
    (ByVal nDrive As String) As Long
    
    Private Const DT_CDROM As Long = 5
    
    Private Sub EnumCDDrives(lstDest As ListBox)
        Dim sDrive As String
        Dim lDrives As Long
        Dim lK As Long
        
        ' Get all drives
        lDrives = GetLogicalDrives()
        
        lstDest.Clear
        
        ' Check all drives
        For lK = 0 To 25
            If (lDrives And 2 ^ lK) <> 0 Then
                ' Get drive root
                sDrive = Chr$(65 + lK) & ":\"
                
                ' Check Type
                If GetDriveType(sDrive) = DT_CDROM Then
                    ' Add it To the list
                    lstDest.AddItem sDrive
                End If
            End If
        Next lK
    End Sub
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  6. #6
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    How about this?

    Code:
    Option Explicit
    Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
    (ByVal nDrive As String) As Long
    
    Private Const DT_CDROM As Long = 5
    
    Private Function CDDrive() As Variant
        Dim SDRN As Byte
        Dim sDrive As String
        Dim Drives() As String
        Dim Count As Byte
    
        Count = 0
        For SDRN = Asc("A") To Asc("Z")
            sDrive = Chr$(SDRN) & ":\"
                
            If GetDriveType(sDrive) = DT_CDROM Then
                Count = Count + 1
                ReDim Drives(0 To Count - 1)
                Drives(Count - 1) = sDrive
            End If
        Next
    
        CDDrive = Drives
    End Function
    This code returns the drives in an array, STARTING WITH 0.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  7. #7
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530

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