Results 1 to 12 of 12

Thread: Closing/opening cdrom drive

  1. #1

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Lightbulb Closing/opening cdrom drive

    Hello...
    This is an API on closing and opening cdrom drive.
    I tried searching for this online and found many for vb6.But,there was none for vb.net.but,finally,I figured it out.I got little bit of help from my friend Oliver too...
    VB Code:
    1. 'This is an API called mcisendstring,a readymade function from the winmm.dll available in windows.
    2.  Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
    3. (ByVal lpszCommand As String, ByVal lpszReturnString As String, _
    4. ByVal cchReturnLength As Long, ByVal hwndCallback As Long) As Long
    5.  
    6.     Private Sub opencd()
    7.         mciSendString("set CDAudio door open", 0, 0, 0) 'here,were sending the command for opening.Its case sensitive and should be EXACT..and same way for closing too. :)
    8.     End Sub
    9.  
    10.     Private Sub closecd()
    11.         mciSendString("set CDAudio door closed", 0, 0, 0)
    12.     End Sub
    Hope this helps someone

    Edit...Thanks to jo0ls for the cdrom lock function too ...Here it is...
    Attached Files Attached Files
    Last edited by uniquegodwin; Dec 10th, 2005 at 06:17 AM.
    Godwin

    Help someone else with what someone helped you!

  2. #2
    New Member
    Join Date
    Jul 2005
    Posts
    7

    Re: Closing/opening cdrom drive

    Hi ,
    It' s good & I was search so long for some thing like , so thanks

  3. #3

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Closing/opening cdrom drive

    Hi Shush..
    Im so happy that this helped you
    Godwin

    Help someone else with what someone helped you!

  4. #4
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    Re: Closing/opening cdrom drive

    Is it possible to disable the door to the drive? On my laptop, if it's barely touched, the door opens.

  5. #5
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Closing/opening cdrom drive

    I dont know how but I know it is possible
    you can "lock" the drive. thats what happens when you're burning a CD also....
    I'm not sure if you can use windows apis to do this, you might need a third party dll?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  6. #6

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Closing/opening cdrom drive

    Hello Mr.Polite and Andy...
    Here...You have it for locking cdrom drive
    http://www.vbforums.com/showthread.p...ighlight=cdrom
    Godwin

    Help someone else with what someone helped you!

  7. #7
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Closing/opening cdrom drive

    nice find
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  8. #8
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    297

    Re: Closing/opening cdrom drive

    Here is how to Load/Unload/Lock/Unlock a drive by its handle (which you can get from the drive letter). It uses deviceIOControl to send commands to the drive, much like the examples in the other thread. I found the command info in the vb6 "Flamed Lib" on pscode.com.
    Attached Files Attached Files
    Last edited by jo0ls; Dec 9th, 2005 at 02:43 PM.

  9. #9

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Closing/opening cdrom drive

    Thank You for posting it here jo0ls..
    ll put it on the 1st post :-)
    Godwin

    Help someone else with what someone helped you!

  10. #10
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    297

    Re: Closing/opening cdrom drive

    In the first post in the thread,
    Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
    (ByVal lpszCommand As String, ByVal lpszReturnString As String, _
    ByVal cchReturnLength As Long, ByVal hwndCallback As Long) As Long
    is wrong, it's using vb6 types, and the sample doesn't allow you to specify the drive:

    VB Code:
    1. Imports System.Runtime.InteropServices
    2. Imports System.Text
    3.  
    4. Public Class CDTray
    5.  
    6.     Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
    7.     (<MarshalAs(UnmanagedType.LPStr)> ByVal command As String, _
    8.     ByVal returnString As StringBuilder, _
    9.     ByVal cchReturnLength As Int32, _
    10.     ByVal hwndCallback As IntPtr) As Int32
    11.  
    12.     ''' <summary>
    13.     ''' Open the specified cdrom drives tray
    14.     ''' </summary>
    15.     ''' <param name="drive">In the form "X:\"</param>
    16.     ''' <remarks></remarks>
    17.     Public Shared Sub OpenCDTray(ByVal drive As String)
    18.         Dim command As String
    19.         ' Here we open a particular drive, and create an alias to it - cddrive:
    20.         command = String.Format("open {0} type cdaudio alias cddrive", drive)
    21.         Dim result As Int32 = mciSendString(command, Nothing, 0, Nothing)
    22.         If result > 0 Then
    23.             Throw New ApplicationException("When opening device, MCISendString returned: " & result)
    24.         End If
    25.         command = "set cddrive door open"
    26.         result = mciSendString(command, Nothing, 0, Nothing)
    27.         If result > 0 Then
    28.             Throw New ApplicationException("When ejecting device tray, MCISendString returned: " & result)
    29.         End If
    30.         command = "close cddrive"
    31.         result = mciSendString(command, Nothing, 0, Nothing)
    32.         If result > 0 Then
    33.             Throw New ApplicationException("When closing device, MCISendString returned: " & result)
    34.         End If
    35.  
    36.     End Sub
    37.  
    38.     ' Close the tray.
    39.     ' Doesn't work for my drive, but deviceIOControl does.
    40.     Public Shared Sub CloseCDTray(ByVal drive As String)
    41.         Dim command As String
    42.         command = String.Format("open {0} type cdaudio alias cddrive", drive)
    43.         Dim result As Int32 = mciSendString(command, Nothing, 0, Nothing)
    44.         If result > 0 Then
    45.             Throw New ApplicationException("When opening device, MCISendString returned: " & result)
    46.         End If
    47.         command = "set cddrive door closed"
    48.         result = mciSendString(command, Nothing, 0, Nothing)
    49.         If result > 0 Then
    50.             Throw New ApplicationException("When closing device tray, MCISendString returned: " & result)
    51.         End If
    52.         command = "close cddrive"
    53.         result = mciSendString(command, Nothing, 0, Nothing)
    54.         If result > 0 Then
    55.             Throw New ApplicationException("When closing device, MCISendString returned: " & result)
    56.         End If
    57.     End Sub
    58.  
    59. End Class

  11. #11

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Closing/opening cdrom drive

    Very nice! Thank you
    Godwin

    Help someone else with what someone helped you!

  12. #12
    Lively Member
    Join Date
    May 2006
    Posts
    84

    Re: Closing/opening cdrom drive

    This is a Great Post, Thx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width