|
■No38848 (魔界の仮面弁士) に追記
>>どうすればよいのでしょうか?
> 幾つかの方法がありますが、たとえばこんなのとか。
第2案。
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
class Program
{
[DllImport("winmm", CharSet = CharSet.Auto)]
private static extern int mciSendString(
string command, StringBuilder buffer,
int bufferSize, IntPtr hwndCallback);
static void Main()
{
foreach (string drive in Environment.GetLogicalDrives())
{
DriveInfo di = new DriveInfo(drive);
if (di.DriveType == DriveType.CDRom)
{
mciSendString("open " + drive + " type cdaudio alias orator", null, 0, IntPtr.Zero);
int canEject = mciSendString("capability orator can eject", null, 0, IntPtr.Zero);
Console.WriteLine("{0}はイジェクト{1}です。", drive, (canEject == 0) ? "可能" : "不可");
Console.WriteLine("ドアを開きます。");
mciSendString("set orator door open", null, 0, IntPtr.Zero);
Console.WriteLine("ドアを締めます。");
mciSendString("set orator door closed", null, 0, IntPtr.Zero);
mciSendString("close orator", null, 0, IntPtr.Zero);
}
}
}
}
|