我的电脑有两个光驱,如何用VB6写一个小工具,弹出或关闭指定的光驱?
我在网上找到的都是打开默认的光驱,如何打开指定的一个呢?用下面这个不成功,不知道为什么?
Dim mssg As String * 255
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrRetumString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub Timer1_Timer()
On Error Resume Next
Dim fso, d, pos1 As Integer, drv As String
Dim Flag As Boolean
For i = 1 To Drive1.ListCount - 1
pos1 = InStr(Drive1.List(i), ":")
drv = Left(Drive1.List(i), pos1)
Set fso = CreateObject("Scripting.FileSystemObject")
Set d = fso.GetDrive(drv)
Flag = Fun_FloppyDrive(drv) '判断是否空盘
If d.DriveType = 4 And Flag Then '判断如果是光驱并有光盘在读
If pwd <> "12345678" Then '判断是否合法
i = mciSendString("stop cd", 0&, 0, 0) '清除原先的光驱记录
i = mciSendString("close cd", 0&, 0, 0) '清除原先的光驱记录
i = mciSendString("open " & drv & " type cdaudio alias cd wait shareable", 0&, 0, 0)
i = mciSendString("set cd door open wait", mssg, 255, 0)
MsgBox "非法使用光驱", 64, "警告"
End If
End If
Next
End Sub
Private Function Fun_FloppyDrive(sDrive As String) As Boolean
On Error GoTo err
If Dir(sDrive) <> "" Or Dir(sDrive) = "" Then
Fun_FloppyDrive = True
Exit Function
End If
err:
Fun_FloppyDrive = False
End Function