We help IT Professionals succeed at work.

Search For Multiple CD-ROM's On A Machine

WonHop
WonHop asked
on
Medium Priority
147 Views
Last Modified: 2010-05-02
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
Comment
Watch Question

TimCotteeHead of Software Services
CERTIFIED EXPERT

Commented:
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
Head of Software Services
CERTIFIED EXPERT
Commented:
Missed the Open stuff:

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 Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) 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
                    ShellExecute Me.hwnd, "Open", strFileName, 0&, strDrive & "\FirstFolder\SubFolder\FileName", 1&
                End If
            Case Is = 6
                '"Ram disk"
            Case Else
                '"Unrecognized"
        End Select
        Debug.Print intDrive, strDrive
    Next intDrive
End Sub

Author

Commented:
Thanks Tim.  I will try it tonight.

WonHop
Richie_SimonettiIT Operations
CERTIFIED EXPERT

Commented:
Holly cow! i posted the same code yesterday night and i cannot see it!!!

Author

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

I am sure what happened.

WonHop
Richie_SimonettiIT Operations
CERTIFIED EXPERT

Commented:
:))))
I used the same code for a VBA Word project a time ago.
Cheers
TimCotteeHead of Software Services
CERTIFIED EXPERT

Commented:
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.

Author

Commented:
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.

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

Thanks
WonHop

Explore More ContentExplore courses, solutions, and other research materials related to this topic.