Prevent DVD ROM tray opening?
Prevent DVD ROM tray opening?
Is there a way to programatically do this, so that if the Eject button on the
CD ROM drive is pressed, the door stays closed and doesn't respond/open?
CD ROM drive is pressed, the door stays closed and doesn't respond/open?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
- 666
- Posts: 1033
- Joined: Mon Sep 01, 2003 2:33 pm
this may give you a few idea's PB...
http://support.microsoft.com/default.aspx/kb/165721
I know this is doing something slightly different to what you want, but read between the lines and you should see that everything you require is there
http://support.microsoft.com/default.aspx/kb/165721
I know this is doing something slightly different to what you want, but read between the lines and you should see that everything you require is there

Thanks, I'll take a look and see if can do what I want.
Also, I found this app which does exactly what I want:
http://www.cdrom-lock.de/index_en.html
And it's GPL so it should have the source somewhere. (It's not included
so I'll have to ask the author for it).
Also, I found this app which does exactly what I want:
http://www.cdrom-lock.de/index_en.html
And it's GPL so it should have the source somewhere. (It's not included
so I'll have to ask the author for it).
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
- 666
- Posts: 1033
- Joined: Mon Sep 01, 2003 2:33 pm
DownloadLuCiFeR[SD] wrote:[edit]the source is available via the sourceforge link in the download section[/edit]
Windows 7 & PureBasic 4.4
The CDRom-Lock app is old and doesn't work with XP -- I could still open my
drive even when it was set to "Lock". So that's no good to me at all. I'll have
to look deeper into the link that Lucifer gave me. Thanks to all who replied.
drive even when it was set to "Lock". So that's no good to me at all. I'll have
to look deeper into the link that Lucifer gave me. Thanks to all who replied.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Okay, I can't get it to work. Here's the code I've tried, and there's some VB
code at the following URL which relates to Lucifer's link. Can anyone help?
http://forums.microsoft.com/MSDN/ShowPo ... 3&SiteID=1
code at the following URL which relates to Lucifer's link. Can anyone help?
http://forums.microsoft.com/MSDN/ShowPo ... 3&SiteID=1
Code: Select all
#FSCTL_LOCK_VOLUME=$90018
#FSCTL_DISMOUNT_VOLUME=$90020
letter$="F" ; My DVD ROM drive letter.
hVolume=CreateFile_("\\.\"+letter$+":",#GENERIC_READ,#FILE_SHARE_READ|#FILE_SHARE_WRITE,0,#OPEN_EXISTING,0,0)
Repeat
locked=DeviceIoControl_(hVolume,#FSCTL_LOCK_VOLUME,0,0,0,0,@dwBytesReturned,0)
Sleep_(250)
Until locked
ret=DeviceIoControl_(hVolume,#FSCTL_DISMOUNT_VOLUME,0,0,0,0,@dwBytesReturned,0)
Debug ret
Repeat : Sleep_(1) : ForEver
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
- 666
- Posts: 1033
- Joined: Mon Sep 01, 2003 2:33 pm
Hey PB, that drive lock program does work... just make sure you actually have media in the drive.
It is a known limitation of that program that if a disk is not in the drive it will not lock... well, with certain CD/DVD hardware anyway. Just check the compatability link on the site.
now, your code isn't working because it depends on the PREVENT_MEDIA_REMOVAL structure. to stop the drive ejecting.
I have never tried VB or C++ conversions to PB, but I'll have a crack at it
...
It is a known limitation of that program that if a disk is not in the drive it will not lock... well, with certain CD/DVD hardware anyway. Just check the compatability link on the site.
now, your code isn't working because it depends on the PREVENT_MEDIA_REMOVAL structure. to stop the drive ejecting.
I have never tried VB or C++ conversions to PB, but I'll have a crack at it

Hello PB,
have a Look at this
Greets,
BI2
have a Look at this
Code: Select all
; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=2789&highlight=
; Author: Andreas (updated for PB3.93 by ts-soft)
; Date: 10. November 2003
; OS: Windows
; Demo: No
;#############################
;Lock & Unlock CDRom-Trays
;Open & Close CDRom-Trays
;#############################
;Lock & Unlock only
;NT4, XP and Win2000
;#############################
;Author : Andreas
;November 2003
;#############################
#IOCTL_STORAGE_MEDIA_REMOVAL = $2D4804
#IOCTL_STORAGE_EJECT_MEDIA = $2D4808
#IOCTL_STORAGE_LOAD_MEDIA = $2D480C
#ListViewGadget = 100
#Lock = 101
#UnLock = 102
#Eject = 104
#Load = 105
#Quit = 106
Global WaitCur.l,ArrowCur.l
WaitCur = LoadCursor_(0,#IDC_WAIT)
ArrowCur = LoadCursor_(0,#IDC_ARROW)
Structure PREVENT_MEDIA_REMOVAL
P1.b
EndStructure
Structure LWInfo
Drive.s
IsLock.b
EndStructure
Global NewList LW.LWInfo()
Procedure GetCDLW()
Protected a.l,Buffer.s
ListViewGadget(#ListViewGadget,10,10,200,200)
*Buffer = AllocateMemory(255)
GetLogicalDriveStrings_(255,*Buffer)
Repeat
If PeekS(*Buffer + b) = ""
Break
EndIf
Buffer = PeekS(*Buffer + b)
SHGetFileInfo_(Buffer,0,SHF.SHFILEINFO,270,769)
If GetDriveType_(Buffer) = #DRIVE_CDROM
AddGadgetItem(#ListViewGadget,-1, PeekS(SHF+12))
AddElement(LW())
LW()\Drive = Mid(PeekS(SHF+12),FindString(PeekS(SHF+12),":",0)-1,2)
LW()\IsLock = 0
EndIf
b = b + 4
ForEver
FreeMemory(*Buffer)
EndProcedure
Procedure EjectCD(LW.s)
SetCursor_(WaitCur)
Protected hLwStatus.l
hLwStatus = CreateFile_("\\.\"+LW,#GENERIC_READ|#GENERIC_WRITE, 0, 0, #OPEN_EXISTING, 0, 0)
If hLwStatus
DeviceIoControl_(hLwStatus,#IOCTL_STORAGE_EJECT_MEDIA,0,0,0,0,@Ret,0)
CloseHandle_(hLwStatus)
EndIf
SetCursor_(ArrowCur)
EndProcedure
Procedure LoadCD(LW.s)
SetCursor_(WaitCur)
Protected hLwStatus.l
hLwStatus = CreateFile_("\\.\"+LW,#GENERIC_READ|#GENERIC_WRITE, 0, 0, #OPEN_EXISTING, 0, 0)
If hLwStatus
DeviceIoControl_(hLwStatus,#IOCTL_STORAGE_LOAD_MEDIA,0,0,0,0,@Ret,0)
CloseHandle_(hLwStatus)
EndIf
SetCursor_(ArrowCur)
EndProcedure
Procedure.l LockCD(Lock.b,LW.s)
Protected LW$,RetBuffer.l,hLwStatus.l
Dim p.PREVENT_MEDIA_REMOVAL(0)
p(0)\P1 = Lock
hLwStatus = CreateFile_("\\.\"+LW,#GENERIC_READ|#GENERIC_WRITE, 0, 0, #OPEN_EXISTING, 0, 0)
If hLwStatus
;LOCK or UNLOCK CD-TRAY
Retval.l = DeviceIoControl_(hLwStatus, #IOCTL_STORAGE_MEDIA_REMOVAL,p(0),SizeOf(BYTE),@p(0),SizeOf(BYTE),@RetBuffer,0)
CloseHandle_(hLwStatus)
EndIf
ProcedureReturn Retval
EndProcedure
Procedure Repair()
ResetList(LW())
While NextElement(LW())
; alle Locks rückgängig machen
LockCD(0,LW()\Drive)
Wend
DeleteObject_(WaitCur)
DeleteObject_(ArrowCur)
End
EndProcedure
Procedure ErrorMessage()
MessageRequester("Info","Kein Laufwerk gewählt",#MB_OK|#MB_ICONINFORMATION)
EndProcedure
If OpenWindow(0,0,0,320,230,"Lock-CDTray",#PB_Window_ScreenCentered|#PB_Window_SystemMenu) And CreateGadgetList(WindowID(0))
GetCDLW()
ButtonGadget(#Lock, 220, 10, 80,20,"Lock")
ButtonGadget(#UnLock, 220, 40, 80,20,"UnLock")
ButtonGadget(#Eject, 220, 70, 80,20,"Eject")
ButtonGadget(#Load, 220, 100, 80,20,"Load")
ButtonGadget(#Quit, 220, 190, 80,20,"Quit")
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #Quit
Repair()
Case #Eject
If GetGadgetState(#ListViewGadget) > -1
SelectElement(LW(),GetGadgetState(#ListViewGadget))
EjectCD(LW()\Drive)
Else
ErrorMessage()
EndIf
Case #Load
If GetGadgetState(#ListViewGadget) > -1
SelectElement(LW(),GetGadgetState(#ListViewGadget))
LoadCD(LW()\Drive)
Else
ErrorMessage()
EndIf
Case #Lock
If GetGadgetState(#ListViewGadget) > -1
SelectElement(LW(),GetGadgetState(#ListViewGadget))
If LW()\IsLock = 0
If LockCD(1,LW()\Drive)
LW()\IsLock = 1
EndIf
EndIf
Else
ErrorMessage()
EndIf
Case #UnLock
If GetGadgetState(#ListViewGadget) > -1
SelectElement(LW(),GetGadgetState(#ListViewGadget))
LockCD(0,LW()\Drive)
Else
ErrorMessage()
EndIf
EndSelect
Case #PB_Event_CloseWindow
Repair()
EndSelect
ForEver
EndIf
; ExecutableFormat=Windows
; FirstLine=1
; EnableXP
; EOF
Greets,
BI2
-
- 666
- Posts: 1033
- Joined: Mon Sep 01, 2003 2:33 pm