How to Eject a CD

  • Thread starter Thread starter Allen St.Clair
  • Start date Start date
Hi,

[DllImport( "winmm.dll", EntryPoint="mciSendStringA",
CharSet=CharSet.Ansi )]
protected static extern int mciSendString( string lpstrCommand,
StringBuilder lpstrReturnString,
int uReturnLength,
IntPtr hwndCallback );

To open CDRom Tray:

string strDriveLetter = "E";
mciSendString( "open "+strDriveLetter+":\\ type cdaudio alias cdrom",
null, 0, IntPtr.Zero );
int ret = mciSendString( "set cdrom door open", null, 0, IntPtr.Zero );
mciSendString( "close cdrom", null, 0, IntPtr.Zero );

To close CDRom Tray:
string strDriveLetter = "E";
mciSendString( "open "+strDriveLetter+":\\ type cdaudio alias cdrom",
null, 0, IntPtr.Zero );
int ret = mciSendString( "set cdrom door closed", null, 0, IntPtr.Zero
);
mciSendString( "close cdrom", null, 0, IntPtr.Zero );

Cheers.

Eyal.
 
Back
Top