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:
'This is an API called mcisendstring,a readymade function from the winmm.dll available in windows.
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
Private Sub opencd()
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. :)
End Sub
Private Sub closecd()
mciSendString("set CDAudio door closed", 0, 0, 0)
End Sub
Hope this helps someone
Edit...Thanks to jo0ls for the cdrom lock function too ...Here it is...
Last edited by uniquegodwin; Dec 10th, 2005 at 06:17 AM.
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!!
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!!
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.
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:
Imports System.Runtime.InteropServices
Imports System.Text
Public Class CDTray
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(<MarshalAs(UnmanagedType.LPStr)> ByVal command As String, _
ByVal returnString As StringBuilder, _
ByVal cchReturnLength As Int32, _
ByVal hwndCallback As IntPtr) As Int32
''' <summary>
''' Open the specified cdrom drives tray
''' </summary>
''' <param name="drive">In the form "X:\"</param>
''' <remarks></remarks>
Public Shared Sub OpenCDTray(ByVal drive As String)
Dim command As String
' Here we open a particular drive, and create an alias to it - cddrive:
command = String.Format("open {0} type cdaudio alias cddrive", drive)
Dim result As Int32 = mciSendString(command, Nothing, 0, Nothing)
If result > 0 Then
Throw New ApplicationException("When opening device, MCISendString returned: " & result)
End If
command = "set cddrive door open"
result = mciSendString(command, Nothing, 0, Nothing)