From: "Primoz Gabrijelcic" Subject: Re: EJECT CDROM UNDER NT Date: 05 Mar 1999 00:00:00 GMT Message-ID: <7bo37t$5q69@forums.borland.com> References: <36DF0C6B.4260FDB9@t-online.de> <36e31ca8.2501574@forums.inprise.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Organization: Another Netscape Collabra Server User Newsgroups: borland.public.delphi.winapi Stefan Hoffmeister wrote: >Search DejaNews. I posted code that SUCKS IN a CD tray quite a while >back. And do search the past archive. Probably good to add >"DeviceIoControl" to that search term, otherwise you'll be swamped >with rubbish (my rubbish, so I may say so ). If I remember correctly, your code was not really working as you left out some constants that are not declared in Windows.pas. I had to convert them from .h macros :-( Anyway, this works for me. Largely that is your original post so you should get most of the credits. const FILE_DEVICE_MASS_STORAGE = $2D; METHOD_BUFFERED = 0; FILE_ANY_ACCESS = 0; FILE_READ_ACCESS = 1; FILE_WRITE_ACCESS = 2; IOCTL_STORAGE_EJECT_MEDIA = (FILE_DEVICE_MASS_STORAGE shl 16) OR (FILE_READ_ACCESS shl 14) OR ($202 shl 2) OR (METHOD_BUFFERED); IOCTL_STORAGE_LOAD_MEDIA = (FILE_DEVICE_MASS_STORAGE shl 16) OR (FILE_READ_ACCESS shl 14) OR ($203 shl 2) OR (METHOD_BUFFERED); var cd: THandle; ret: DWORD; begin // Note: Stefan opened CD-ROM with GENERIC_READ OR GENERIC_WRITE. // That should be correct according to MS documentation but was not working for me. // This (just GENERIC_READ) seems to be working on all computers. cd := CreateFile(PChar('\\.\D:'), GENERIC_READ, 0, nil, OPEN_EXISTING, 0, 0); if CD <> INVALID_HANDLE_VALUE then begin // eject if not DeviceIoControl(cd,IOCTL_STORAGE_EJECT_MEDIA, nil, 0, nil, 0, ret, nil) then { report error }; // load if not DeviceIoControl(cd,IOCTL_STORAGE_LOAD_MEDIA, nil, 0, nil, 0, ret, nil) then { report error }; CloseHandle(cd); end; end; Primoz