前回の投稿で使用したCDデバイス名一覧から選択したCDデバイスを特定する処理です
前投稿[CDデバイス一覧取得]のソースがある前提で
引数に選択したCDデバイス名を指定すれば対応するデバイスのIDを取得します
--------------------------------------------------------------------------------
''' <summary>
''' RecorderUniqueID取得
''' </summary>
Public Function GetCDDevID(sProductId As String) As String
Dim strRet As String = String.Empty
Dim objDiscMaster As IMAPI2.MsftDiscMaster2 = Nothing
Try
'デバイス検索
objDiscMaster = New IMAPI2.MsftDiscMaster2
For Each sDev As String In objDiscMaster
Dim objDev As New IMAPI2.MsftDiscRecorder2
Try
objDev.InitializeDiscRecorder(sDev)
If Trim(objDev.ProductId) = sProductId Then
strRet = sDev
Exit For
End If
Catch ex As Exception
Throw ex
Finally
MarshalObject(objDev)
End Try
Next
Catch ex As Exception
Throw ex
Finally
MarshalObject(objDiscMaster)
End Try
Return strRet
End Function
''' RecorderUniqueID取得
''' </summary>
Public Function GetCDDevID(sProductId As String) As String
Dim strRet As String = String.Empty
Dim objDiscMaster As IMAPI2.MsftDiscMaster2 = Nothing
Try
'デバイス検索
objDiscMaster = New IMAPI2.MsftDiscMaster2
For Each sDev As String In objDiscMaster
Dim objDev As New IMAPI2.MsftDiscRecorder2
Try
objDev.InitializeDiscRecorder(sDev)
If Trim(objDev.ProductId) = sProductId Then
strRet = sDev
Exit For
End If
Catch ex As Exception
Throw ex
Finally
MarshalObject(objDev)
End Try
Next
Catch ex As Exception
Throw ex
Finally
MarshalObject(objDiscMaster)
End Try
Return strRet
End Function
--------------------------------------------------------------------------------
これだけだと面白くないのでCDトレーのEJECTをさせる処理を
引数に選択したCDデバイス名を指定すれば対応するデバイスのトレーを開きます
--------------------------------------------------------------------------------
''' <summary>
''' EJECT TRAY
''' </summary>
''' <param name="sProductId">Device名</param>
Public Sub TrayEJECT(sProductId As String)
Dim objRecorder As New IMAPI2.MsftDiscRecorder2
Dim sRecorderUniqueID As String = GetCDDevID(sProductId)
Try
If Not String.IsNullOrWhiteSpace(sRecorderUniqueID) Then
'デバイス決定
objRecorder.InitializeDiscRecorder(sRecorderUniqueID)
'EJECT
objRecorder.EjectMedia()
End If
Catch ex As Exception
Throw ex
Finally
MarshalObject(objRecorder)
End Try
End Sub
--------------------------------------------------------------------------------
0 件のコメント:
コメントを投稿