ejecting cdrom in .net
using this code:
public class DvdRomUtility
{
[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi)]
protected static extern int mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, IntPtr hwndCallback);
public static void Open(string driveName)
{
int ret = mciSendString("set cdaudio door open", null, 0, IntPtr.Zero);
}
public static void Close(string driveName)
{
int ret = mciSendString("set cdaudio door closed", null, 0, IntPtr.Zero);
}
}
i can open and close my dvd rom. but i want know DVDrom's door is open or close because i want a method to when i call it IF:
1- dvd rom's door is open then dvd rom's door will close
2- dvd rom's door is close then dvd rom's door will open
thanks
Have you take a look at "DeviceIoControl" ? See MSDN and P/Invoke.Net for samples and details, especially the StorageEjectMedia and StorageLoadMedia commands.
Edit: And for sample code, it is here.
Have you tried using System.IO.DriveInfo.IsReady ?
精彩评论