471,349 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,349 software developers and data experts.

How to Eject a CD

How can I eject a CD tray (Drive Letter is known)?

Thx~
Jul 21 '05 #1
2 3614
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.

Jul 21 '05 #2
Thx~.
"Eyal Safran" <ey**@mokedor.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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.

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Prakru | last post: by
1 post views Thread by Hai Ly Hoang [MT00KSTN] | last post: by
3 posts views Thread by Tony | last post: by
reply views Thread by MT00KSTN - Hai Ly Hoang | last post: by
4 posts views Thread by Maheshkumar.R | last post: by
2 posts views Thread by Allen St.Clair | last post: by
3 posts views Thread by Joe Cool | last post: by
reply views Thread by David Penne | last post: by
4 posts views Thread by John Devlon | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.