?
Solved

Lock CDROM door

Posted on 2000-03-03
4
Medium Priority
?
441 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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

765 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