foreach (var drive in DriveInfo.GetDrives() .Where(d => d.DriveType == DriveType.CDRom)) MessageBox.Show(drive.name + " " + drive.IsReady.ToString());
从here.
DriveType Enumeration可以帮你什么样的光盘:
> CDRom:驱动器是光盘设备,例如CD或DVD-ROM.
>修正:驱动器是固定磁盘.
>网络:驱动器是网络驱动器.
> norootDirectory驱动器没有根目录.
> Ram:驱动器是RAM磁盘.
>可移动:驱动器是可移动存储设备,例如软盘驱动器或USB闪存驱动器.
>未知:驱动器类型未知.
对于CD / DVD /蓝光的种类见IMAPI_MEDIA_PHYSICAL_TYPE enumeration:
>未知
> CDROM
> CDR
> CDRW
> DVDROM
> DVDRAM
> DVdplUSR
> DVdplUSRW
> DVdplUSR_DUALLAYER
> DVDDASHR
> DVDDASHRW
> DVDDASHR_DUALLAYER
>磁盘
> DVdplUSRW_DUALLAYER
> HDDVDROM
> HDDVDR
> HDDVDRAM
> BDROM
> BDR
> BDRE
> MAX
你的代码可能是这样的:
public bool IsdiscAvailable(int driveNumber){ MsftdiscMaster2Class discMaster = new MsftdiscMaster2Class(); string ID = discMaster[driveNumber]; MsftdiscRecorder2Class recorder = new MsftdiscRecorder2Class(); recorder.InitializediscRecorder(ID); MsftdiscFormat2DataClass dataWriter = new MsftdiscFormat2DataClass(); if (dataWriter.IsRecorderSupported(recorder)) { dataWriter.Recorder = recorder; } else { Console.Writeline("Recorder not supported"); return false; } if (dataWriter.IsCurrentMediaSupported(recorder)) { var media = dataWriter.CurrentPhysicalMediaType; if (media == IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNowN) { Console.Writeline("UnkNown media or no disc"); } else { Console.Writeline("Found disc type {0}",media); return true; } } else { Console.Writeline("disc absent or invalID."); } return false;}
从here.
总结以上是内存溢出为你收集整理的c# – 检测光盘是否在DVD驱动器中全部内容,希望文章能够帮你解决c# – 检测光盘是否在DVD驱动器中所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)