VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



HOW CAN I KNOW THE CDROM DRIVE LETTER IN ANY COMPUTER

by MOHAMED A HAFEZ (1 Submission)
Category: Windows API Call/Explanation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 22nd April 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

HOW CAN I KNOW THE CDROM DRIVE LETTER IN ANY COMPUTER

API Declarations


Const DRIVE_FIXED = 3
Const DRIVE_REMOTE = 4
Const DRIVE_CDROM = 5
Const DRIVE_RAMDISK = 6


Rate HOW CAN I KNOW THE CDROM DRIVE LETTER IN ANY COMPUTER



Public Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
----------------------------------------------


Private Sub Command1_Click()
  Dim r&, allDrives$, JustOneDrive$, pos%, DriveType&
  Dim CDfound As Integer
   
  'pad the string with spaces
   allDrives$ = Space$(64)
  
  'call the API to get the string containing all drives
   r& = GetLogicalDriveStrings(Len(allDrives$), allDrives$)
  
  'trim off trailing chr$(0)'s.  AllDrives$
  'now contains all the drive letters.
   allDrives$ = Left$(allDrives$, r&)
   
  'begin a loop
   Do
      
     'find the first separating chr$(0)
      pos% = InStr(allDrives$, Chr$(0))
      
     'if there's one, then...
      If pos% Then
        
       'extract the drive up to the chr$(0)
        JustOneDrive$ = Left$(allDrives$, pos%)
        
       'and remove that from the Alldrives string,
       'so it won't be checked again
        allDrives$ = Mid$(allDrives$, pos% + 1, Len(allDrives$))
      
       'with the one drive, call the API to
       'determine the drive type
        DriveType& = GetDriveType(JustOneDrive$)
        
       'check if it's what we want
        If DriveType& = DRIVE_CDROM Then
          
          'got it (or at least the first one,
          'anyway, if more than one), so set
          'the found flag...
           CDfound% = True

          'we're done, so get out
           Exit Do
        
        End If
      End If
   
  Loop Until allDrives$ = "" Or DriveType& = 6
   
 'display the appropriate message
  If CDfound% Then
        Label1 = UCase$(JustOneDrive$)
  Else: Label1 = "NO CDROM DRIVE..!!"
  End If

End Sub


Download this snippet    Add to My Saved Code

HOW CAN I KNOW THE CDROM DRIVE LETTER IN ANY COMPUTER Comments

No comments have been posted about HOW CAN I KNOW THE CDROM DRIVE LETTER IN ANY COMPUTER. Why not be the first to post a comment about HOW CAN I KNOW THE CDROM DRIVE LETTER IN ANY COMPUTER.

Post your comment

Subject:
Message:
0/1000 characters