Solved

Lock CDROM door

Posted on 2000-03-03
4
438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
code issue 8 184
Correct Component for Shopping Cart. 2 121
How to renew a Delphi rad-studio licence? 5 77
Dev express lookupcombo 3 45
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 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