I want to create a small program in C# in Windows that would open the CD drive tongue – eject the CD if there is one. I’d like to know where to start with this.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Opening and closing a disk drive programmatically in C# is not all that difficult thanks to a useful API function called mciSendStringA.
First you will need to define the function that will be opening the disk tray:
If the code above does not compile try adding the following C# line at the very top of your source code:
Opening the Disk Drive
To open the disk drive you need to send two command strings using mciSendStringA. The first one will assign a name to the desired drive. The second command will actually open the disk tray:
Closing the Disk Drive
To close the disk drive you need to send two command strings once again. The first one will be the same. The second command will now close the disk tray: