does anyone know how to make the software automatically open a specific cd rom drive?
if you happen to know a string of code that does this, it would be appreciated...
Printable View
does anyone know how to make the software automatically open a specific cd rom drive?
if you happen to know a string of code that does this, it would be appreciated...
in vb 6.0 you would use API try it...
VB Code:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long Private Sub cmdOpenCD_Click() Dim lRet As Long lRet = mciSendString("set CDAudio door open", returnstring, 127, 0) End Sub Private Sub cmdCloseCD_Click() Dim lRet As Long lRet = mciSendString("set CDAudio door closed", returnstring, 127, 0) End Sub
that one didn't work, but thanks... if anyone else has one i can try i'd appreciate it...
It is working but you have to change every Long there to Integer and put the Returnstring in "":Shoutouts go to Genom of course.VB Code:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer 'then to open: Dim lRet As Long lRet = mciSendString("set CDAudio door open", "returnstring", 127, 0) 'and to close: Dim lRet2 As Long lRet2 = mciSendString("set CDAudio door closed", "returnstring", 127, 0)
that didn't work for me either... do i install that on a button or will it do it automatically?
i'm a noob... so i need some help... i never would have figured out any of that so far...
Yes, the 'Private Declare Function etc...' is outside any procedure, then putin a button click.VB Code:
Dim lRet As Long lRet = mciSendString("set CDAudio door open", "returnstring", 127, 0)
only for info
VB Code:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
is a declaration of a function which shows to software that there is a function in that dll file and make it ready to use. we put them always outside an event or a function.
ok, i got the string in with no errors, but when i click the button... nothing happens...
hi Conflix
I Need The Same Thing As You
Have You Sorted ?
Plz Post The Working One
Thanks
Here is a complete example:
Opens the CD tray and then after 2 seconds it closes too.
Code:Option Explicit On
Option Strict On
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("winmm.dll", CharSet:=CharSet.Auto, EntryPoint:="mciSendString")> _
Private Shared Function mciSendString( _
ByVal lpstrCommand As String, _
ByVal lpstrReturnString As String, _
ByVal uReturnLength As Integer, _
ByVal hwndCallback As Integer) As Integer
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lRet As Long
lRet = mciSendString("set CDAudio door open", "returnstring", 127, 0)
System.Threading.Thread.Sleep(2000)
lRet = mciSendString("set CDAudio door closed", "returnstring", 127, 0)
End Sub
End Class
Here is a sub to open a specific CDRom tray using Window Media Player. You need to add a reference to Windows Media Player COM object to your project
For example, if you want to open the tray of the E: CDRom drive, you just callCode:Imports WMPLib
Private Sub EjectCDRom(ByVal driveName As String)
Dim player As WMPLib.WindowsMediaPlayer = Nothing
Try
player = New WMPLib.WindowsMediaPlayer
Dim count As Integer = player.cdromCollection.count
If count > 0 Then
For n As Integer = 0 To count - 1
If (player.cdromCollection.Item(n).driveSpecifier).StartsWith(driveName.ToUpper) Then
player.cdromCollection.Item(n).eject()
Exit For
End If
Next
End If
Catch ex As Exception
Throw ex
Finally
player = Nothing
End Try
End Sub
Code:EjectCDRom("E:")
Thank You Guy