Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-11
5
Medium Priority
?
687 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 11

Accepted Solution

by:
Sudhakar Pulivarthi earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 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