Solved

how can i open cd/dvd drive using C#.net  window application ??

Posted on 2011-03-11
5
664 Views
Last Modified: 2012-05-11
how can i open cd/dvd drive using C#.net  window application ??

can u please tell me ?
0
Comment
Question by:Parth48
  • 3
5 Comments
 
LVL 3

Expert Comment

by:4runnerfun
ID: 35108059
//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
0
 
LVL 3

Expert Comment

by:4runnerfun
ID: 35108065
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
0
 
LVL 3

Expert Comment

by:4runnerfun
ID: 35108076
0
 
LVL 11

Accepted Solution

by:
Sudhakar Pulivarthi earned 500 total points
ID: 35108305
Hi,
You have to use winmm.dll API
//Import winmm.dll        
[DllImport("winmm.dll")]        
static extern Int32 mciSendString(String command, StringBuilder buffer, Int32 bufferSize, IntPtr hwndCallback);        
private void Close()        
{            
//Closes the Cd Tray            
mciSendString("set CDAudio door closed", null, 0, IntPtr.Zero);        
}        
private void open()        
{            
//Opens the Cd Tray of your cd Drive            
mciSendString("set CDAudio door open", null, 0, IntPtr.Zero);        
}

0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 35109509
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);
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question