How To Eject And Close CD/DVD Drive In C#

How To Eject And Close CD/DVD Drive In C#
Okay guys i was doing a program about managing the system things so i had to figure out eject and closing CD/DVD Drive so i did and here is the code for this .

first of all you need to import a interop service it's

   [DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi)]
        protected static extern int mciSendString(string lpstrCommand,
        StringBuilder lpstrReturnString,
        int uReturnLength,
        IntPtr hwndCallback);
        
after importing it add the namespace using System.Runtime.InteropServices; , then add this code to eject CD/DVD Drive

            int ret = mciSendString("set cdaudio door open", null, 0, IntPtr.Zero);

now to close CD/DVD Drive use this code


            int ret = mciSendString("set cdaudio door closed", null, 0, IntPtr.Zero);

Hope it helped you ..

3 comments

Hey Can we create a textbox like fb?
I mean : where we can use smilies in textbox

Reply

i am not that good at css and web developments indeed

Reply

Thank you man, this code was very helpfull for me.
Can u explain in detail the sintax of this pieces of code??....

Reply

Post a Comment

Note: Only a member of this blog may post a comment.