Link to home
Start Free TrialLog in
Avatar of WonHop
WonHopFlag for United States of America

asked on

Search For Multiple CD-ROM's On A Machine

Hello All.   I need to search for ALL CD-ROM?s on a machine.
What I need for it to do is:
Search for the first CD-ROM,  
Get the Drive Letter.
Put it in a variable.
Look for a file in a specified Folder on the CD.
Ex: strDriveLetter:\FirstFolder\SubFolder\FileName
If it finds the program, then OPEN then program.
If it doesn?t find it on that one, then search for the next CD-ROM

I don't have VB on my machine here at work.  So I will have to try it at home.  So if at all possible, I am looking for Proven Working Code.
My response to how well it works will be done the next day.

Thanks
WonHop
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Something like this:

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

Private Sub Command1_Click()
    Dim strSave As String
    Dim strDrive As String
    Dim intDrive As Integer
    Dim rst As Long
    Dim strFileName As String
    On Error Resume Next
    strSave = String(255, Chr(0))
    ret = GetLogicalDriveStrings(255, strSave)
    For intDrive = 1 To 100
        strDrive = Left(strSave, InStr(1, strSave, Chr(0)) - 1)
        If strDrive = "" Then Exit For
        strSave = Right(strSave, Len(strSave) - InStr(1, strSave, Chr(0)))
        Select Case GetDriveType(strDrive)
            Case 2
                '"Removable"
            Case 3
                '"Drive Fixed"
            Case Is = 4
                '"Remote"
            Case Is = 5
                '"Cd-Rom" So check for file:
                strFileName = ""
                strFileName = Dir(strDrive & "\FirstFolder\SubFolder\FileName")
                If strFileName <> "" Then
                    MsgBox "The File Exists On Drive " & strDrive
                End If
            Case Is = 6
                '"Ram disk"
            Case Else
                '"Unrecognized"
        End Select
        Debug.Print intDrive, strDrive
    Next intDrive
End Sub
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WonHop

ASKER

Thanks Tim.  I will try it tonight.

WonHop
Avatar of Richie_Simonetti
Holly cow! i posted the same code yesterday night and i cannot see it!!!
Avatar of WonHop

ASKER

Maybe Tim replaced his name with yours!!!  ha ha ha....(Just Kidding)

I am sure what happened.

WonHop
:))))
I used the same code for a VBA Word project a time ago.
Cheers
You must have cobbled together the same bits of sample code that I did then. Not too much of a surprise really as I guess you have pretty much the same set of resources as I do for some things.
Avatar of WonHop

ASKER

Thanks Tim.  The code worked great!
I had to Dim ret As String, but other than that, it worked fine.

I just added a comment on my other question that is kinda similar to this if either you would like to take a look at it.

https://www.experts-exchange.com/jsp/qManageQuestion.jsp?qid=20269565

Thanks
WonHop