Link to home
Start Free TrialLog in
Avatar of Parth48
Parth48Flag for India

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 ?
Avatar of 4runnerfun
4runnerfun

//private field:
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
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
ASKER CERTIFIED SOLUTION
Avatar of Sudhakar Pulivarthi
Sudhakar Pulivarthi
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SAMIR BHOGAYTA
Hi, use the following code.


using System.Runtime.InteropServices;
[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);