You can get it from WMI. Win32_CDROMDrive class.
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT MediaType FROM Win32_CDROMDrive"); ManagementObjectCollection collection = searcher.Get(); foreach (ManagementBaseObject obj in collection) { MessageBox.Show(obj["MediaType"].ToString()); }
This will be a problem if you need to know about BDRom, etc. I recommend using NeroCmd tools instead of WMI.
You can also try looking here . It's about burning, but there you can find supported disk media. If it supports Blu-ray media, then this is obviously not a CD-ROM :)
I tried to get only the important parts. Here we use the IMAPI2 API to get device functions (CD / DVD / BD / HDDVD-READ). I know that there are COMBO disks that support BD and HDDVD, but I do not show them in the code.
// // Determine the current recording devices // MsftDiscMaster2 discMaster = null; try { discMaster = new MsftDiscMaster2(); if (!discMaster.IsSupportedEnvironment) return; // Get drives foreach (string uniqueRecorderId in discMaster) { IDiscRecorder2 discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(uniqueRecorderId); // Show device mount drive and determine type Console.WriteLine("Path: {0} Type: {1}", discRecorder2.VolumePathNames[0], CheckType(discRecorder2)); } } catch (COMException ex) { Console.WriteLine("Error:{0} - Please install IMAPI2", ex.ErrorCode); } finally { if (discMaster != null) Marshal.ReleaseComObject(discMaster); }
Magic ^ _ ^
// Determine type static string CheckType(IDiscRecorder2 disc) { var features = disc.SupportedFeaturePages.Select(a => (IMAPI_FEATURE_PAGE_TYPE)a).ToArray(); if (features.Contains(IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_HD_DVD_READ)) return "HD-DVD-ROM"; if (features.Contains(IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_BD_READ)) return "BD-ROM"; if (features.Contains(IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_DVD_READ)) return "DVD-ROM"; if (features.Contains(IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_CD_READ)) return "CD-ROM"; return "Unknown"; }
Interop ...
According to MSDN, IMAPI_FEATURE_PAGE_TYPE may not only contain these values, so be careful.
source share