C#如何判断DVD驱动器托盘打开? [英] C# How to tell if DVD drive tray is open?

查看:174
本文介绍了C#如何判断DVD驱动器托盘打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中的DVD读取和刻录应用程序。我希望能够检测到一个空驱动器(无硬盘)和开放的驱动器之间的差异



编辑:经过一些google搜索,我想一个更好的问题说明在我要访问的驱动器托盘状态 - 打开或关闭



我可以使用

  ManagementObjectSearcher(SELECT * FROM的Win32_LogicalDisk WHERE的DriveType = 5)

找到在系统中的所有DVD驱动器,和属性告诉我,如果有在驱动器中的磁盘。 访问属性告诉我,如果有一个空白的磁盘。



访问为空时,驱动器是开放的,并且在驱动关闭而空。而且我没有看到,当驱动器打开或关闭改变任何其它属性。



任何人都知道的一种方式,从一个封闭的空驱动器区分一个开放带动<? / p>

我使用Win7的,但最好的解决办法将在XP和Vista也行。


解决方案

MediaLoaded财产(Win32_CDROMDrive)会告诉你是否有一个盘装。我就是你要找有点迷茫什么:




  1. 光盘托盘打开

  2. 光盘托盘关闭 - 没有媒体

  3. 光盘托盘关闭 - 有媒介



MediaLoaded属性将的情况下,2帮助(假)和3(真)


I have a DVD reading and burning app in C#. I want to be able to detect the difference between an empty drive (no disk) and an open drive.

Edit: After some more googling, I think a better problem description is "I want to access the drive tray status - open or closed"

I can use

ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk WHERE DriveType= 5")

to find all the dvd drives in the system, and the properties tell me if there is a disk in the drive. Access property tells me if there is a blank disk.

But Access is null when the drive is open, and when the drive is shut and empty. And I don't see any other property that changes when the drive opens or closes.

Anyone know a way to distinguish an open drive from a closed and empty drive?

I am using Win7, but ideally the solution would work on XP and Vista also.

解决方案

MediaLoaded property (Win32_CDROMDrive) will tell you whether you have a disc loaded. I am bit confused what you are looking for:

  1. disk tray open
  2. disk tray closed - no media
  3. disk tray closed - has media

MediaLoaded property will help in case 2 (False) and 3 (True)

这篇关于C#如何判断DVD驱动器托盘打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆