Parth48
asked on
how can i open cd/dvd drive using C#.net window application ??
how can i open cd/dvd drive using C#.net window application ??
can u please tell me ?
can u please tell me ?
Sorry lol. Didn't notice the not support portion. Try this link.
http://www.geekpedia.com/tutorial174_Opening-and-closing-the-CD-tray-in-.NET.html
http://www.geekpedia.com/tutorial174_Opening-and-closing-the-CD-tray-in-.NET.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi, use the following code.
using System.Runtime.InteropServ ices;
[DllImport("winmm.dll")]
static extern Int32 mciSendString(String command, StringBuilder buffer, Int32 bufferSize, IntPtr hwndCallback);
mciSendString("set CDAudio door open", null, 0, IntPtr.Zero);
mciSendString("set CDAudio door closed", null, 0, IntPtr.Zero);
// Open Drive H:
mciSendString("open H: type CDAudio alias driveH", null, 0, IntPtr.Zero);
mciSendString("set driveH door open", null, 0, IntPtr.Zero);
// Open Drive I:
mciSendString("open I: type CDAudio alias driveI", null, 0, IntPtr.Zero);
mciSendString("set driveI door open", null, 0, IntPtr.Zero);
// Close Drive H:
mciSendString("open H: type CDAudio alias driveH", null, 0, IntPtr.Zero);
mciSendString("set driveH door closed", null, 0, IntPtr.Zero);
// Close Drive I:
mciSendString("open I: type CDAudio alias driveI", null, 0, IntPtr.Zero);
mciSendString("set driveI door closed", null, 0, IntPtr.Zero);
using System.Runtime.InteropServ
[DllImport("winmm.dll")]
static extern Int32 mciSendString(String command, StringBuilder buffer, Int32 bufferSize, IntPtr hwndCallback);
mciSendString("set CDAudio door open", null, 0, IntPtr.Zero);
mciSendString("set CDAudio door closed", null, 0, IntPtr.Zero);
// Open Drive H:
mciSendString("open H: type CDAudio alias driveH", null, 0, IntPtr.Zero);
mciSendString("set driveH door open", null, 0, IntPtr.Zero);
// Open Drive I:
mciSendString("open I: type CDAudio alias driveI", null, 0, IntPtr.Zero);
mciSendString("set driveI door open", null, 0, IntPtr.Zero);
// Close Drive H:
mciSendString("open H: type CDAudio alias driveH", null, 0, IntPtr.Zero);
mciSendString("set driveH door closed", null, 0, IntPtr.Zero);
// Close Drive I:
mciSendString("open I: type CDAudio alias driveI", null, 0, IntPtr.Zero);
mciSendString("set driveI door closed", null, 0, IntPtr.Zero);
private long setTrayStatus;
//API
//use this code to open the tray:
// ERROR: Not supported in C#: DeclareDeclaration
setTrayStatus = mciSendString("Set CDAudio Door Open", null, 0, 0);
//use this code to close the tray:
setTrayStatus = mciSendString("Set CDAudio Door Closed", null, 0, 0);
converted from vb.net - reference at:
http://www.dreamincode.net/code/snippet469.htm