Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining CD Rom Drive Letter 2

Status
Not open for further replies.

mishmish

Programmer
May 25, 2001
27
0
0
US
Hi,

Does anyone know how to determine in code the cd rom drive letter of a user's machine.

Thanks,
mishmish
 
I believe I have some code at home that can do this, I will check tonight and get back to you tomorrow.

Joe Miller
joe.miller@flotech.net
 
Put this in a new module, then call it using
Drive_Type("C") or whichever drive you are testing

Option Compare Database
Option Explicit
Public ndrive As String
Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal ndrive As String) As Long

Public Function Drive_Type(driveletter As Variant) As Long

'Function returns type of drive based on passed drive letter
' 'Return Values
' '0=Can't Identify drive (error)
' '1=Drive Not Present
' '2=Removable (Floppy disk or Zip drive type)
' '3=Fixed (Hard Drive or Non-Removable Zip drive)
' '4=Remote (Network Drive)
' '5=CDROM
' '6=RAMDISK
ndrive = Left$(driveletter, 1) + ":\"
Drive_Type = GetDriveType(ndrive)
Select Case Drive_Type
Case 0
MsgBox "Can't Identify the Drive type"
Case 1
MsgBox "Drive type is " & "Not Present"
Case 2
MsgBox "Drive type is " & "Removable (Floppy disk or Zip drive type)"
Case 3
MsgBox "Drive type is " & "Fixed (Hard Drive or Non-Removable Zip drive)"
Case 4
MsgBox "Drive type is " & "Remote (Network Drive)"
Case 5
MsgBox "Drive type is " & "CD-ROM"
Case 6
MsgBox "Drive type is " & "RAM Disk"
End Select
End Function

PaulF
 
additional info... if you want to test for drive letters A to Z then

Dim i As Integer, MyDriveLetter As String
For i = 65 To 90
MyDriveLetter = Chr(i)
If Drive_Type(MyDriveLetter) = 5 Then
MsgBox "Drive " & MyDriveLetter & " is a CD Drive"
'or do something else
End If
Next i

PaulF
 
Nice stuff Paul, guess I'm the loser on this one! :) Joe Miller
joe.miller@flotech.net
 
Hi Paul,

Thanks a lot for that. That worked great!

mishmish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top