Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have a CDROM drive which is ready (I think so, because I can open a disc using it without having any problem), but I tried getting its volume label and there was an exception saying "The device is not ready":

Here is my code:
C#
DriveInfo cd = new DriveInfo("F"); //My CD ROM drive
MessageBox.Show(cd.VolumeLabel)

How can I get its volume label?

Your help would be highly appreciated! Thanks!
Posted
Updated 17-Sep-12 5:59am
v2
Comments
Alan N 17-Sep-12 12:20pm    
The volume label is associated with a disk. Is there one in the drive?
[no name] 17-Sep-12 13:03pm    
I think that you probably have the right answer here.
supernorb 17-Sep-12 13:28pm    
Thank you, why didn't you give your answer to my question?
Yeah, my drive didn't have any disk, and after inserting a one, it worked! Thanks again!

However, my CD Ejector became useless when it can't eject my CD Drive when the drive has a disk, I just tested when the drive didn't have a disk. I collected the code at StackOverFlow, well, it seems to be rather complicated, I used winmm.dll and it works well, but with CreateFile and dozens of other functions don't work!
[no name] 17-Sep-12 16:19pm    
Maybe your Drive is busy. I mean another program is using the Drive.

1 solution

Check for cd.IsReady flag,if it is false the device is not actually ready and you can put the code to sleep and try again.If it is always false then there is a problem with the Drive.
 
Share this answer
 
Comments
supernorb 17-Sep-12 13:15pm    
Of course, the cd.IsReady is false, but in fact there is not any problem with my drive, it is still working properly.
My want is how to get the VolumeLabel of a CD ROM drive, my approach using DriveInfo seems to be not feasible, Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900