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 ..