VB获取U盘盘符
我要做一个维护工具,其中需要在插入新的U盘时得到U盘的盘符,可是具体怎么做却没有思路,请各位帮我用VB6写出这种效果吧。。。...
我要做一个维护工具,其中需要在插入新的U盘时得到U盘的盘符,可是具体怎么做却没有思路,请各位帮我用VB6写出这种效果吧。。。
展开
若以下回答无法解决问题,邀请你更新回答
展开全部
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 Form_Click()
Dim iscd As Boolean
Dim StrDrive As String '盘符串(A:\ C:\ D:\...)
Dim DriveID As String '盘符(如:A:\)
iscd = False
StrDrive = String(100, Chr$(0)) '初始化盘符串
Call GetLogicalDriveStrings(100, StrDrive) '返回盘符串
Dim i As Integer
'返回光盘盘符到数组
For i = 1 To 100 Step 4 '注意这里是4
DriveID = Mid(StrDrive, i, 3) '枚举盘符
If GetDriveType(DriveID) = 2 Then
s = Mid(StrDrive, i, 3)
msgbox "可移动盘的盘符为 " & s
exit for
end if
If DriveID = Chr$(0) & Chr(0) & Chr(0) Then Exit For '没有盘符,即时退出循环
Next i
End Sub
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Sub Form_Click()
Dim iscd As Boolean
Dim StrDrive As String '盘符串(A:\ C:\ D:\...)
Dim DriveID As String '盘符(如:A:\)
iscd = False
StrDrive = String(100, Chr$(0)) '初始化盘符串
Call GetLogicalDriveStrings(100, StrDrive) '返回盘符串
Dim i As Integer
'返回光盘盘符到数组
For i = 1 To 100 Step 4 '注意这里是4
DriveID = Mid(StrDrive, i, 3) '枚举盘符
If GetDriveType(DriveID) = 2 Then
s = Mid(StrDrive, i, 3)
msgbox "可移动盘的盘符为 " & s
exit for
end if
If DriveID = Chr$(0) & Chr(0) & Chr(0) Then Exit For '没有盘符,即时退出循环
Next i
End Sub
追问
呃。。。怎样可以排除软盘驱动器A:\...每次都会弹出来。。。
追答
For i = 1 To 100 Step 4 '注意这里是4
改成
For i = 5 To 100 Step 4 '注意这里是4
跳过软驱
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询