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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding the CD-Rom drive 1

Status
Not open for further replies.

jjhobs

Instructor
Sep 18, 2003
27
GB
I want to be able to use the package and deployment wizard to create a setup file which, when installed, uses photos still on the CD-Rom. Therefore, my VB software needs to be able to locate the CD-Rom drive which, of course, could be different on different machines. Could anybody help me with the code to do this? Thanks.
 
Here's a start.
Make sure to reference the Micorsoft Scripting Runtime

Dim fso As New Scripting.FileSystemObject
Dim drives As Scripting.Drive
For Each drives In fso.drives
If drives.DriveType = CDRom Then
'Check if this is the correct cd rom if so
'execute code and exit for if not check for next cd rom
MsgBox "The Cd Rom Drive letter is " & drives.DriveLetter
End If
Next
 
You can also get the information by using the API to enumerate the available drives, and to determine if one is a CD-ROM or not...

give me an email at m<dot>milan<at>blueyonder<dot>co<dot>uk if you need a hand with it...

mmilan
 
> needs to be able to locate the CD-Rom drive

Just remember that the &quot;drive&quot; may be &quot;drive(s)&quot;.
I wanted to point that out as it can be a common mistake.

Good luck!
 
mmilan
Please read faq222-2244 paragraph 12 to see why email questions and answers are discouraged in this forum

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
jjhobs, did you get this or any of your other issues in the other threads resolved?
 
DrJavaJoe - I have only just tried to use your code and it comes up with an error &quot;user defined type not defined&quot;. Do you have any ideas what I could be doing wrong?

With regards to your question about my other threads, I have resolved them. Thanks.
 
>Do you have any ideas what I could be doing wrong?


Yes, you missed &quot;Make sure to reference the Micorsoft Scripting Runtime&quot; in DrJavaJoe's post
 
Thanks for this, but how do I reference it?
 
Project Menu -> References -> Micorsoft Scripting Runtime

&quot;Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.&quot;
 
DrJavaJoe - Thanks. I am very grateful for your help. I have one more question, however - if there is more than one CD rom drive, how do I check if it is the correct one?

Thanks again
jjHobs
 
I have used the code recommended by DrJavaJoe on December 17 as follows:

I have referenced the Micorsoft Scripting Runtime

Dim fso As New Scripting.FileSystemObject
Dim drives As Scripting.Drive
For Each drives In fso.drives
If drives.DriveType = CDRom Then
'Check if this is the correct cd rom if so
'execute code and exit for if not check for next cd rom
MsgBox &quot;The Cd Rom Drive letter is &quot; & drives.DriveLetter
End If
Next

To check if it is the correct cd rom drive I have used the dir function to check for a file on the CD. This seems to return error 52 if the file doesn't exist, so I have included error trapping. However, the error trapping works fine for the first cdRom drive without a disk in, but when it comes across the second cdRom drive without a disk I get a run time error 52. Can anyone suggest why this might be, or whether there is a better way of checking if it is the correct drive.

Thanks
jjhobs
 
You can call the FileExists Method of the FileSystemObject object.
Dim fso As New Scripting.FileSystemObject
Dim drives As Scripting.Drive
For Each drives In fso.drives
If drives.DriveType = CDRom Then
'Check if this is the correct cd rom if so
'execute code and exit for if not check for next cd rom
If fso.FileExists(drives.DriveLetter & &quot;:\TheFileName&quot;) Then
'Do Something
Else
MsgBox &quot;The File Doesn't exist&quot;
End If

End If
Next

&quot;Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.&quot;
 
Thanks for everybody's help throughout my problems. All have now been resolved.

jjhobs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top