Solved

Lock CDROM door

Posted on 2000-03-03
4
432 Views
Last Modified: 2010-04-04
I am using Delphi 2.
How should I code in order to prevent the CDROM door from being opened?  The CDROM door should not open even when the user press the "Eject" button on the CDROM drive.  Of course, software ejecting, such as CD players should also be prevented.
Thx!
0
Comment
Question by:nyt
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 2582515
hi,
you can use the DeviceIOControl functions:
(note this only works in win9* not nt ,as you may be aware to acccess hardware under nt you need a device driver which cant be done in delphi)


type
TRegDWord = packed record
case Integer of
0 : (Lo,Hi : Word);
1 : (X : DWord);
end;

TDevIoCtl_Reg = packed record
Reg_BX : DWord;
Reg_DX : DWord;
Reg_CX : DWord;
Reg_AX : DWord;
Reg_DI : DWord;
Reg_SI : DWord;
Reg_Flags : DWord;
end;

TParamBlock = packed record
PB_Operation : Byte;
PB_NumLocks : Byte;
end;

const
VWin32_DIOC_DOS_IoCtl = 1; // interrupt 21h

function DriveCharToNum(Drivechar : Char) : Word;
begin
DriveChar:=Upcase(DriveChar);
Result:= Ord(DriveChar)-Ord('A')+1;
end;

function AccessDevice(Var Reg : TDevIoCtl_Reg) : Integer;
var
DevIoHandle : THandle;
BytesReturned : DWord;
Res : Boolean;
begin
Result:=-1;
Reg.Reg_Flags:=$0001;
DevIoHandle :=
CreateFile('\\.\vwin32',0,0,nil,0,File_Flag_Delete_On_Close,0);
if DevIoHandle <> Invalid_Handle_Value then begin
Res :=
DeviceIoControl(DevIoHandle,VWin32_DIOC_DOS_IoCtl,@Reg,SizeOf(Reg),@Reg,SizeOf(Reg),BytesReturned,nil); if (Res and ((Reg.Reg_Flags and $0001) = 0)) Then Result:=0
else Result:=Reg.Reg_AX;
CloseHandle(DevIoHandle);
end;
end;

function DriveEject(DriveChar : Char) : Integer;
Var
Reg : TDevIoCtl_Reg;
begin
with Reg do begin
Reg_AX := $440d;
Reg_CX := $0849;
Reg_BX := DriveCharToNum(Drivechar);
Reg_Flags := $0001;
end;
Result:=AccessDevice(Reg);
end;

function DriveLock(DriveChar : Char) : Integer;
Var
Reg : TDevIoCtl_Reg;
Param : TParamBlock;
begin
With Param DO begin
PB_Operation:=0;
PB_NumLocks :=0;
end;
with Reg do begin
Reg_AX := $440d;
Reg_BX := DriveCharToNum(Drivechar);
Reg_CX := $0848;
Reg_DX := Integer(@Param);
end;
Result:=AccessDevice(Reg);
end;
0
 
LVL 4

Expert Comment

by:Romi Kuntsman
ID: 2849378
I tried this code, but i couldn't unlock my drive without using 'DriveEject' which ofcourse ejected my drive... :-(
So what about unlocking the CDROM drive?! (without ejecting it!!!)
0
 

Author Comment

by:nyt
ID: 2852700
Maybe different versions of Delphi would have different results.  However, it works fine for my D2.
0
 
LVL 4

Expert Comment

by:Romi Kuntsman
ID: 2853131
What works?! The answer doesn't contain a 'DriveUnlock' function!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now