For Answers, see/post comments

Open the CD TRAY using c# code

The following Code will help us to Open CD Tray By using C# Language:

using System;
using System.Collections.Generic;
using System.Linq;using System.Text;
using System.Runtime.InteropServices;

namespace play
{
class Program
{
[DllImport("winmm.dll")]

public static extern void mciSendString(string s1,string s2, int i,int j);

static void Main(string[] args)
{
char ch;
Console.Write("Enter 'O' to open CD Tray! : ");
ch = Console.ReadKey().KeyChar;

if (ch =='O' ch == 'o')
{
mciSendString("set cdaudio door open",null,0,0);
}

Console.WriteLine();
Console.Write("Enter 'C' to close CD Tray! : ");
ch=Console.ReadKey().KeyChar;

if (ch == 'C' ch == 'c')
{
mciSendString("set cdaudio door closed", null, 0, 0);
}

}
}
}

No comments: