vb6.0如何判断驱动器是光盘(DVD驱动器或CD驱动器)

来源:百度知道 编辑:UC知道 时间:2024/05/26 14:45:22
比如输入光盘符号F:如何判断他是否是光盘,如果是则显示插入磁盘的对话框,就像在电脑里双击DVD盘一样,如果里面有光盘着不提示,如何实现。

'新建工程,添加一个listbox,一个CommandButton
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Private Sub Command1_Click()
Dim StrDrive As String '获取盘符
Dim DriveID As String '盘符(如:A:\)
StrDrive = String$(120, Chr$(0)) '初始化盘符串
Call GetLogicalDriveStrings(120, StrDrive) '返回盘符串
Dim i As Integer
For i = 1 To 120 Step 4 '注意这里是4
DriveID = Mid$(StrDrive, i, 3) '枚举盘符
List1.AddItem DriveID
If DriveID = Chr$(0) & Chr$(0) & Chr$(0) Then Exit For '没有盘符,即时退出循环
If GetDriveType(DriveID) = 2 Then
MsgBox DriveID & "是U盘!"
'Shell "attrib +s +h " & DriveID & "*.* /s /d", vbNormalFocus '调用attrib设置隐藏
End