C#打开关闭CDROM!

 

引入命名空间:

using System.Runtime.InteropServices;

添加如下代码:

[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi)]

protected static extern int mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, IntPtr hwndCallback);

实现代码:

int ret = mciSendString("set cdaudio door open", null, 0, IntPtr.Zero); // 打开

Console.ReadLine();

ret = mciSendString("set cdaudio door closed", null, 0, IntPtr.Zero); // 关闭

 

 

 

你可能感兴趣的:(C#打开关闭CDROM!)