VB基础问题,高手解答,非常感谢!

2024-12-02 17:30:43
推荐回答(1个)
回答1:

用fso可以做到 参考代码为

Private Sub Form_Load()
aa "c:\"
aa "d:\"
aa "e:\"
aa "f:\"
aa "g:\"
aa "h:\"
End Sub
Sub aa(a)
Set fso = CreateObject("Scripting.FileSystemObject")
Select Case fso.GetDrive(a).DriveType
Case 1
MsgBox Left(a, 1) & "盘是可移动磁盘"
Case 2
MsgBox Left(a, 1) & "盘是硬盘"
Case 4
MsgBox Left(a, 1) & "盘是光盘"
End Select
End Sub

代码二:
Private Sub Form_Load()
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
a = fso.GetDrive("h:\").DriveType
If a = 2 Then
MsgBox "是U盘"
ElseIf a <> 0 Then
MsgBox "不是U盘"
Else
MsgBox "没有检测到任何盘"
End If
End Sub