This will return the first CD-ROM Drive
using System.Runtime.InteropServ
...
[DllImport("kernel32.dll")
public static extern uint GetDriveType(string driveLetter);
public string GetCDDrive()
{
foreach(string s in Environment.GetLogicalDriv
{
if (GetDriveType(s)==5) return s;
}
return null;
}
Main Topics
Browse All Topics





by: SaltePosted on 2003-07-08 at 09:31:26ID: 8878496
This can be tricky since the computer may have more than one drive and there is really no way to know which drive the user has placed the CD in now.
However, you can simply check each of the CD drives in turn and check if they have the folder you're looking for. Perhaps also double check with a volume label of the CD etc...
Typically you should then save the path once it is found and next time you try the path you found last time. If user removes the CD from the drive you can then check the other CD drives (all CD drives should be cached in a collection) If you don't find the CD anywhere ask the user to insert the CD into a CD drive and then retry the search.
You should probably wrap all of this into a class that manages the CD access and also keep a cache of all CD drives on the system (not likely to change while the program is running) and which CD drive have the CD disk in (might change while the program is running).
Hope this is of help.
Alf