reading the system registry

how can I detect the currentdriveletter property of the cd-rom in the registry from vb.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

                                                           'Windows API/Global Declarations for :Ge
                                                           '     tLogicalDriveLetter

                                                           Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

                                                           Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

                                                            Option Explicit
                                                            Const DRIVE_CDROM = 5
                                                            Const DRIVE_FIXED = 3
                                                            Const DRIVE_RAMDISK = 6
                                                            Const DRIVE_REMOTE = 4
                                                            Const DRIVE_REMOVABLE = 2

                                                            Private Function GetLogicalDriveLtr(strType As String) As String
                                                                Dim tmp As Integer
                                                                Dim tmpstr As String
                                                                Dim Drives As String
                                                                Dim CDsCount As Integer
                                                                Dim ZipCount As Integer
                                                                Dim DriveLtr As String
                                                                Dim ret As Integer
                                                                'init Drives to 255 spaces
                                                                Drives = Space(255)
                                                                ret = GetLogicalDriveStrings(Len(Drives), Drives)

                                                                For tmp = 1 To ret Step 4
                                                                    'get a drive root directory (like "C:\")
                                                                    tmpstr = Mid(Drives, tmp, 3)
                                                                    'if drive is a CD

                                                                    If strType = "CDROM" Then

                                                                        If GetDriveType(tmpstr) = DRIVE_CDROM Then
                                                                            CDsCount = CDsCount + 1
                                                                            GetLogicalDriveLtr = tmpstr
                                                                        End If
                                                                    ElseIf strType = "ZIPDISK" Then
                                                                        ' A Zip disk is considered to be of type
                                                                        '     Drive_Removable.
                                                                        If (GetDriveType(tmpstr) = DRIVE_REMOVABLE) And _
                                                                        (Trim(tmpstr) <> "a:\") Then
                                                                        ZipCount = ZipCount + 1
                                                                        GetLogicalDriveLtr = tmpstr
                                                                    End If
                                                                End If
                                                            Next tmp

                                                            If CDsCount = 0 Then
                                                                MsgBox "No CDs Available"
                                                            End If

                                                            If ZipCount = 0 Then
                                                                MsgBox "No Zip drives installed."
                                                            End If
                                                            End Function

Copy and paste the code intpo a form and run the application

Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Sub Form_Load()
Dim i As Integer
Dim strString As String

For i = vbKeyA To vbKeyZ
    strString = UCase(Chr(i)) & ":\"
    If GetDriveType(strString) = 5 Then
        MsgBox Chr(i) & " : is a CD-ROM Drive"
    End If

End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

You can find the current drive letter in the registry in the key HKEY_LOCAL_MACHINE\Enum\SCSI\
Depending on the type of CDROM drive you are using, which will usualy vary from one machine to the next, the full registry key will be something like this:
The drive letter could be found under CurrentDriveLetterAssignment

jackgAuthor Commented:
although the solution does fit the bill, I think it is rather long winded and looks as if it has been pasted from a manual or other source.
jackgAuthor Commented:
very tidy piece of code vbguru thanks for the assist, any ideas how I can detect the current directory as I need this for an app install procedure. I have tried getcurrentdirectory using winapi call but this generates an error, I am using VB 6.00.
There was a problem in declarion copied from the api-viewer. I am using VB5.0. Check out the following code, it may work in vb6.0

Option Explicit
Private Declare Function GetCurrentDirectoryA Lib "kernel32" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Private Sub Form_Load()
Dim i As String
i = String(200, Chr$(0))
GetCurrentDirectoryA 200, i
MsgBox i
End Sub
jackgAuthor Commented:
vbguru, thanks it worked fine
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.