Results 1 to 2 of 2

Thread: Switching the Defalt CD drive

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    313

    Question

    Is there a way to switch the defalt CD drive. Because I have 2 cd drives, and I am useing an eject statment. I just want to switch the defalt. Nothing fancy on the eject statment.

  2. #2
    Addicted Member
    Join Date
    Jul 2000
    Location
    Scotland
    Posts
    184
    here is some code that gets the first CD drive, you may be able to amend it to return a named drive, or simply deal with the first if its your default

    Code:
    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

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