我想从 .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/