|
-
Dec 6th, 2001, 03:06 AM
#1
Thread Starter
New Member
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
-
Dec 6th, 2001, 05:13 AM
#2
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:
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
For i = 1 to 26
Select Case GetDriveType(chr(64+i) & ":\")
Case 2 ' "Removable"
Case 3 ' "Drive Fixed"
Case 4 ' "Remote"
Case 5 ' "Cd-Rom"
' do something here!
msgbox chr(64+i) & "is a CD drive"
Case 6 ' "Ram disk"
Case Else ' "Unrecognized"
End Select
Next i
-
Dec 6th, 2001, 07:32 AM
#3
VB Code:
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
Private Const DRIVE_CDROM = 5
Private CDRom As Variant
Private Sub Detect_CD_Rom()
'
'Usage:
'Detect_CD_ROM
'Msgbox CD_ROM
'
Dim retval As Long
Dim allDrives As String
Dim JustOneDrive As String
Dim MyPosition As Integer
Dim DriveType As Long
Dim CDfound As Boolean
allDrives = Space$(64)
retval = GetLogicalDriveStrings(Len(allDrives), allDrives)
allDrives = Left$(allDrives, retval)
Do
MyPosition = InStr(allDrives, Chr$(0))
If MyPosition Then
JustOneDrive = Left$(allDrives, MyPosition)
allDrives = Mid$(allDrives, MyPosition + 1, Len(allDrives))
DriveType& = GetDriveType(JustOneDrive)
If DriveType& = DRIVE_CDROM Then
CDfound = True
Exit Do
End If
End If
Loop Until allDrives = "" Or DriveType& = DRIVE_CDROM
If CDfound = True Then
CDRom = Trim(UCase(JustOneDrive))
Else
CDRom = "?"
End If
MsgBox CDRom
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|