CD-ROM Tray Locking

I know how to programmatically open/close the CD-ROM tray, but I need to be able to lock/unlock the tray - prevent it from opening by pressing the button.

LVL 1
cvidlerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vbyuvalCommented:
I wish I knew !
0
cvidlerAuthor Commented:
I hope you just clicked the 'Answer' option by accident...
0
master01Commented:
How bout this,

Place a timer on the form
set the interval to 1
have it send the MCISENDSTRING "CLOSE" to the cdrom at each interval.  therefore if the user presses the open button on the cdrom at the next millisecond the cdrom will close.

GoOd LuCk!

Lee
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

cvidlerAuthor Commented:
Unfortuanetly this is what I have treid before, and the constant accessing slows down the programs that need the CD drive far too much.

No I know how to open/close the tray using MCI

"set cdaudio door open"
or
"set cdaudio door closed"

is there are "door locked/unlocked"???
0
mcriderCommented:
Unfortunately, there is no door lock/unlock... however, instead of sending the MCISendString "Close" on a timer, you could try it with a windows hook... This doesn't take up the resources of a timer...

Here is some example code that will notify you when the CD is opened and closed via Windows hook.  Just modify it to send the MCISendString instead of issuing the CD open messagebox...

Hope this helps!


Cheers!


THE CODE:

This example creates a windows hook on form1 and notifies you when a CD is mounted and unmounted.

1) Create a new project.

2) Add two commandbuttons to the form.  Name them "cmdHook" and "cmdUnHook".

3) Add the following code to the DECLARATIONS SECTION of Form1:

    Private Sub cmdHook_Click()
        Hook
    End Sub
    Private Sub cmdUnHook_Click()
        UnHook
    End Sub
    Private Sub Form_Load()
        gHW = Me.hWnd
    End Sub

4) Add the following code to a MODULE:

    Global lpPrevWndProc As Long
    Global gHW As Long
    Public Const GWL_WNDPROC = -4
    Public Const WM_DEVICECHANGE = 537
    Public Const DBT_DEVICEARRIVAL = 32768
    Public Const DBT_DEVICEREMOVECOMPLETE = 32772
    Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
           (ByVal lpPrevWndFunc As Long, _
            ByVal hWnd As Long, _
            ByVal Msg As Long, _
            ByVal wParam As Long, _
            ByVal lParam As Long) As Long
    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
           (ByVal hWnd As Long, _
            ByVal nIndex As Long, _
            ByVal dwNewLong As Long) As Long
    Public Sub Hook()
        lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
    End Sub
    Public Sub UnHook()
        Dim lngReturnValue As Long
        lngReturnValue = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
    End Sub
    Function WindowProc(ByVal hw As Long, _
                        ByVal uMsg As Long, _
                        ByVal wParam As Long, _
                        ByVal lParam As Long) As Long
        Select Case uMsg
            Case WM_DEVICECHANGE 'CHECK FOR THE DEVICE CHANGE MESSAGE
                Select Case wParam
                    Case DBT_DEVICEARRIVAL ' DISK MOUNTED
                        MsgBox "CD Inserted"
                    Case DBT_DEVICEREMOVECOMPLETE 'DISK UNMOUNTED
                        MsgBox "CD Removed"
                    Case Else
                        Debug.Print "wParam:", wParam
                End Select
            Case Else
                WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
        End Select
    End Function


5) Run the program and click the "cmdHook" Button.

6) Eject the CD.

7) Insert a CD.

8) Eject the CD.

9) Click the "cmdUnHook" button.

10) Stop the program.

YOU MUST UNHOOK THE WINDOWS HOOK BEFORE STOPPING THE PROGRAM, OTHERWISE IT WILL CRASH!


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cvidlerAuthor Commented:
I'll give it a try - but I know their is a better way - how do those little DOS utils work (because they don't stay TSR)

there is also a prog called WinEject which will do it for you...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.