Results 1 to 2 of 2

Thread: Drive letter

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Posts
    21

    Question

    How can i get CD ROM drive letter or other drives?
    Golpesar

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    you need one button on a form called cmdGetDrives
    then paste this code into the form

    Code:
    Option Explicit
    Option Base 0
    Private Declare Function GetDriveType Lib "KERNEL32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    Private Declare Function GetLogicalDrives Lib "KERNEL32" () As Long
    Private Const DR_REMOVABLE = 2
    Private Const DR_FIXED = 3
    Private Const DR_REMOTE = 4
    Private Const DR_CDROM = 5
    Private Const DR_RAMDISK = 6
    
    Private Sub cmdGetDrives_Click()
    Dim aDriveInfo() As String
    Dim i&
    aDriveInfo = DrivesAndTypes
    For i = LBound(aDriveInfo) To UBound(aDriveInfo)
      Debug.Print aDriveInfo(i)
    Next i
    End Sub
    
    Public Function MakeDriveLetter(sDrive$) As String
      MakeDriveLetter = CStr(sDrive) & ":\"
      Exit Function
    End Function
    
    Public Function DrivesAndTypes() As String()
        Dim LDs&, Cnt&, sDrives$, sCurrentDrive$
        Dim aHolder() As String
        LDs = GetLogicalDrives
        For Cnt = 0 To 25
            If (LDs And 2 ^ Cnt) <> 0 Then
            ReDim Preserve aHolder(Cnt)
                sCurrentDrive = MakeDriveLetter(Chr$(65 + Cnt))
              Select Case GetDriveType(sCurrentDrive)
                Case DR_REMOVABLE
                  aHolder(Cnt) = sCurrentDrive & " Is Removable"
                Case DR_FIXED
                                  aHolder(Cnt) = sCurrentDrive & " Is Fixed"
                Case Is = DR_REMOTE
                                  aHolder(Cnt) = sCurrentDrive & " Is Remote"
                Case Is = DR_CDROM
                                  aHolder(Cnt) = sCurrentDrive & " Is a CD Drive"
                Case Is = DR_RAMDISK
                                  aHolder(Cnt) = sCurrentDrive & " Is a RAM Disk"
                Case Else
                              aHolder(Cnt) = sCurrentDrive & " Is Unknown"
        End Select
            End If
        Next Cnt
      DrivesAndTypes = aHolder
    End Function
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

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