Public Sub ejectCDRom() Dim i As Integer 'code to eject cdrom ok Dim owmp As Object Dim colCDROMs As Object owmp = CreateObject("WMPlayer.OCX.7") colCDROMs = owmp.cdromCollection If colCDROMs.Count >= 1 Then For i = 0 To colCDROMs.Count - 1 colCDROMs.Item(i).eject() Next End If End Sub
Public Class Form1 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 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim CDTrayOpen As Boolean = False 'this is global 'this is in the click event If CDTrayOpen Then 'Close CD tray mciSendString("set CDAudio door closed", 0, 0, 0) CDTrayOpen = False Else 'Open CD tray mciSendString("set CDAudio door open", 0, 0, 0) CDTrayOpen = True End If End Sub End Class
Last Updated on October 26, 2015