Solved

Lock CDROM door

Posted on 2000-03-03
4
433 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

910 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

20 Experts available now in Live!

Get 1:1 Help Now