标题:我的电脑有两个光驱,如何用VB6写一个小工具,弹出或关闭指定的光驱?
只看楼主
y526892224
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2008-8-11
结帖率:100%
 问题点数:0 回复次数:0 
我的电脑有两个光驱,如何用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   
搜索更多相关主题的帖子: 工具 光驱 
2010-04-04 20:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-301684-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.376705 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved