We help IT Professionals succeed at work.

Open(Eject) And Close CD-ROM Tray in code....How to do ?

DOOM_DAEMON
DOOM_DAEMON asked
on
       I know that Delphi can open CD-Rom Tray (Eject) But I don't know how to close it in code...Anyone outthere can show me a fully coded procedure to do so...I want it to open(Eject) and Close with a Button "Open" and "Close" Shown on form...
Comment
Watch Question

Software Developer
CERTIFIED EXPERT
Commented:

uses mmsystem;

procedure TForm1.Button1Click(Sender: TObject);
begin
//To OPEN the CD-ROM:
mciSendString
  ('Set cdaudio door open wait', nil, 0, handle);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
//{To CLOSE the CD-ROM:}
mciSendString
  ('Set cdaudio door closed wait', nil, 0, handle);
end;
This is the code I was using a while ago to do what you need, but I'm not sure if it works still.

To open the CD-ROM:

mciSendString('Set cdaudio door open wait', nil, 0, handle);

To close the CD-ROM:

mciSendString('Set cdaudio door closed wait', nil, 0, handle);

You need to have MMSystem declared in your uses clause.

HIH.

Stu.
Damn you have to be quick ;)  In the time it took me to open Explorer, locate the project, open the PAS file, copy and paste it, the same code was already provided.  You're fast mnasman :)

Stu

Commented:
Hi Stuart,

Its a kind of Magic. Create your own Knowledge Base to store some Tricks & Tips an Artikes ;-)

Some Experts here are using Clients. This clients tell us there is a new Question.......

Have a nice live

Cesario

Commented:
What would the commands be if you have more than one cd-rom? In other words a cd-rom and a cd-writer.

Commented:
Dear skynergy,

AFAIK the device name in Specified in the SYSTEM.INI file.

Example:
[mci]
cdaudio=mcicda.drv
sequencer=mciseq.drv
waveaudio=mciwave.drv
avivideo=mciavi.drv
videodisc=mcipionr.drv
vcr=mcivisca.drv
MPEGVideo=mciqtz.drv
MPEGVideo2=mciqtz.drv


Best Regards

Cesario

Commented:
Thanx for your quick response!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.