|
-
Jul 25th, 2001, 03:34 PM
#1
Thread Starter
Frenzied Member
Detecting CD drive..
Hi,
I'm creating an application that will need to browse a CD-Rom in the CD drive to get certain files.
My question is, how do you detect the user's CD drive letter? Also, what if the user has moer than 1 cd drive, such as a cd and a cd-writer? How would I know which one to browse?
Any help and example code would be appreciated..
Dan
-
Jul 25th, 2001, 03:36 PM
#2
PowerPoster
I'm creating an application that will need to browse a CD-Rom in the CD drive to get certain files.
The common dialog control will work with that, wouldn't it?
-
Jul 25th, 2001, 03:56 PM
#3
Use the GetDriveType API.
VB Code:
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Const DRIVE_CDROM = 5
'Returns an array with all the CD Drive's
Function GetCDDrives() As Variant
Dim vDrives() As Variant
Dim iCount As String
iCount = 0
For I = Asc("A") To Asc("Z")
If GetDriveType(Chr$(I) & ":") = DRIVE_CDROM Then
ReDim vDrives(iCount)
vDrives(iCount) = Chr$(I)
End If
Next I
GetCDDrives = vDrives
End Function
Usage:
VB Code:
v = GetCDDrives
For I = LBound(v) To UBound(v)
Print v(I)
Next I
-
Jul 25th, 2001, 05:31 PM
#4
New Member
How to detect CD
got your answer:
Private Declare Function GetDriveType Lib "kernel32" Alias _
"GetDriveTypeA" (ByVal nDrive As String) As Long
Private Const DRIVE_CDROM = 5
Public Function GetCDROMDriveLetter() As String
Dim DriveChar As Byte
'Dim tmpDrive As String
GetCDROMDriveLetter = "Unknown"
On Error GoTo ErrorHandler
For DriveChar = 0 To 25
tmpDrive = Chr(65 + DriveChar) & ":\"
If (GetDriveType(tmpDrive) = DRIVE_CDROM) Then
GetCDROMDriveLetter = tmpDrive
varDrive = tmpDrive
Exit For
End If
Next DriveChar
'varDrive = tmpDrive
ErrorHandler:
Exit Function
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|