Results 1 to 3 of 3

Thread: getting cdroms drive letter

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Gorakhpur
    Posts
    2

    Exclamation getting cdroms drive letter

    Hello
    I want to get the drive letter associated to cdrom from my vb code.Hope I will some one who is going to help me out of this question.
    thanx for reading
    Nupur

  2. #2
    Si_the_geek
    Guest
    Here's a simple bit of code, but watch out - lots of people have multiple CD drives (CD reader & writer, or CD and DVD), so you should allow for that in your code...
    VB Code:
    1. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    2.  
    3.   For i = 1 to 26
    4.     Select Case GetDriveType(chr(64+i) & ":\")
    5.         Case 2  ' "Removable"
    6.         Case 3  ' "Drive Fixed"
    7.         Case 4  ' "Remote"
    8.         Case 5  ' "Cd-Rom"
    9. ' do something here!
    10. msgbox chr(64+i) & "is a CD drive"
    11.         Case 6  ' "Ram disk"
    12.         Case Else  ' "Unrecognized"
    13.     End Select
    14.   Next i

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    2. Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    3.  
    4. Private Const DRIVE_CDROM = 5
    5. Private CDRom As Variant
    6.  
    7. Private Sub Detect_CD_Rom()
    8.     '
    9.     'Usage:
    10.     'Detect_CD_ROM
    11.     'Msgbox CD_ROM
    12.     '
    13.     Dim retval As Long
    14.     Dim allDrives As String
    15.     Dim JustOneDrive As String
    16.     Dim MyPosition As Integer
    17.     Dim DriveType As Long
    18.     Dim CDfound As Boolean
    19.    
    20.     allDrives = Space$(64)
    21.     retval = GetLogicalDriveStrings(Len(allDrives), allDrives)
    22.     allDrives = Left$(allDrives, retval)
    23.     Do
    24.         MyPosition = InStr(allDrives, Chr$(0))
    25.         If MyPosition Then
    26.             JustOneDrive = Left$(allDrives, MyPosition)
    27.             allDrives = Mid$(allDrives, MyPosition + 1, Len(allDrives))
    28.             DriveType& = GetDriveType(JustOneDrive)
    29.  
    30.             If DriveType& = DRIVE_CDROM Then
    31.                 CDfound = True
    32.                 Exit Do
    33.             End If
    34.         End If
    35.     Loop Until allDrives = "" Or DriveType& = DRIVE_CDROM
    36.  
    37.     If CDfound = True Then
    38.         CDRom = Trim(UCase(JustOneDrive))
    39.     Else
    40.        CDRom = "?"
    41.     End If
    42.     MsgBox CDRom
    43. End Sub

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