请问在VB中如何探测到USB的插入和拔出

来源:百度知道 编辑:UC知道 时间:2024/05/30 21:31:21

m fso As FileSystemObject
Dim Dr As Drive
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Private Sub Command1_Click()
Dim fso As New FileSystemObject
For Each Dr In fso.Drives
If GetDriveType(Dr) = 2 Then
Debug.Print Dr.DriveLetter
If Dr.IsReady = True Then
Debug.Print "准备好了"
Else
Debug.Print "没有准备好"
End If
Else

Debug.Print "没有插入USB设备"

End If
Next

End Sub