I started stripping down some IMAPI code to make something to enumerate the cdroms and eject, but it is still enormous, and anyway it will only do burner drives.
So here is another way instead, using windows media players api:
VB Code:
'look in oject browser: com component windows media player (wmp.dll) Dim WithEvents lv As New ListView Dim wmp As Object Dim cdroms As Object Dim cdrom As Object Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lv.View = View.Details lv.Dock = DockStyle.Fill lv.Columns.Add("Cdrom identifier", 100, HorizontalAlignment.Left) lv.MultiSelect = False Me.Controls.Add(lv) wmp = CreateObject("WMPlayer.OCX.7") cdroms = wmp.cdromCollection For i As Long = 0 To wmp.cdromCollection.count - 1 cdrom = cdroms.item(i) Dim lvi As New ListViewItem lvi.Text = cdrom.drivespecifier lvi.Tag = i lv.Items.Add(lvi) Next End Sub 'double click an item to eject Private Sub lv_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lv.DoubleClick If lv.SelectedItems(0) Is Nothing Then Exit Sub Dim index As Integer = lv.SelectedItems(0).Tag ' we stored the cdrom index in the tag cdrom = cdroms.item(index) cdrom.eject() End Sub
I think there might be another way too, I'll pursue it...




Reply With Quote