c# - 我可以从 .NET 中唯一标识 DVDR(W)(+/-) 媒体吗?

标签 c# .net cddvd

我想从 .NET 代码中识别 DVDR 媒体。这是可能的,如何?

某种库,它调用 Windows API。

更新

我有很多 DVDR,我需要识别它们中的每一个,但不依赖于内容或磁盘名称。每个 DVDR 的某种序列号,DVDR 在工厂获得。

最佳答案

您可以使用 IMAPI v2 实现此目的API。

一旦您在 .NET 项目中有了正确的引用,以及在该 API 中定义的各种枚举(并且有相当多的枚举!),代码就相对简单了。类似于(伪代码):

IDiscRecorder2 discRecorder = (IDiscRecorder2)[*cd/dvd drive*];
discFormatData.Recorder = discRecorder;
IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType;
string mediaTypeString = GetMediaTypeString(mediaType);

where:
IMAPI_MEDIA_PHYSICAL_TYPE is an enum such like:

public enum IMAPI_MEDIA_PHYSICAL_TYPE
{
    IMAPI_MEDIA_TYPE_UNKNOWN = 0,
    IMAPI_MEDIA_TYPE_CDROM = 1,
    IMAPI_MEDIA_TYPE_CDR = 2,
    IMAPI_MEDIA_TYPE_CDRW = 3,
    IMAPI_MEDIA_TYPE_DVDROM = 4,
    IMAPI_MEDIA_TYPE_DVDRAM = 5,
    [not the complete enum...snipped for brevity!]
}

and the "GetMediaTypeString" function simply gives a friendly string
representation of the enum name.

CodeProject 网站上有一篇很好的文章和示例项目,相当全面地演示了这一点:

Burning and Erasing CD/DVD/Blu-ray Media with C# and IMAPI2

该项目不仅包含检测媒体类型(因此得名!),还包含在刻录/删除媒体之前有效检测媒体类型的代码。

来自文章:

Determining Media Type

To determine the media type and available space on the hard drive, you create a MsftDiscFormat2Data object and set the current recorder in the Recorder property. You can then get the media type from the IDiscFormat2Data CurrentPhysicalMediaType property.

Once you have the media type, create a MsftFileSystemImage object and call the ChooseImageDefaultsForMediaType method with the media type.

关于c# - 我可以从 .NET 中唯一标识 DVDR(W)(+/-) 媒体吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1164567/

相关文章:

c# - .NET 中的树集合

c# - 如何防止打印屏幕

c# - .Net 应用程序极慢。杀死 svchost.exe 后,它再次快速运行。任何想法?

c# - MVC Windows 身份验证 + 通过 AspNetUserRoles 表进行角色管理

c# - 32 位 C# 应用程序如何利用 64 位 DLL

path - 来自 CD/DVD 驱动器的 Inno Setup 安装脚本(可变路径)

c# - 在 .NET 中创建 CD/DVD ISO 镜像

delphi - 如何从 delphi2007 win32 刻录 CD/DVD

c# - 获取没有 DNS 的网络上所有计算机的列表

java - 如何在不安装 MS Office 且不使用 Interop Library 的情况下读取服务器中的 MS Office 文件?