How to Eject a CD or DVD

This short code Snippet will help you eject a CD or DVD using Windows Media Player API

Public Class frmEject
'you need window media player reference in your project
'1 combo box
' 2 button control
Dim omal As New WMPLib.WindowsMediaPlayer
Dim total As Integer
Dim i As Integer

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
omal.close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
total = 0
i = 0
total = omal.cdromCollection.count
If (total >= 1) Then
For i = 0 To (total - 1)
ComboBox1.Items.Add(omal.cdromCollection.Item(i).driveSpecifier)
Next
ComboBox1.Text = ComboBox1.Items.Item(0)
End If
MyBase.CenterToScreen()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not (ComboBox1.Text = "") Then
omal.cdromCollection.Item(ComboBox1.SelectedIndex).eject()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For i = 0 To (total - 1)
omal.cdromCollection.Item(i).eject()
Next
End Sub
End Class

0 comments:

Post a Comment