Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-11
5
Medium Priority
?
695 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Screencast - Getting to Know the Pipeline
Suggested Courses

963 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