Solved

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

Posted on 2011-03-11
5
652 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
Comment Utility
//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
Comment Utility
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
Comment Utility
0
 
LVL 11

Accepted Solution

by:
Sudhakar Pulivarthi earned 500 total points
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now