怎么用VB获取本机所有的盘符
1个回答
展开全部
Option Explicit
注释:申明API函数
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Sub Form_Load()
注释:声明变量
Dim DrvNum As Single
Dim drvName As String
Dim DrvType As Integer
Dim i As Integer
Me.AutoRedraw = True
Drive1.Visible = False
注释:获取所有常规磁盘信息——
DrvNum = Asc("a") - 1
For i = 0 To Drive1.ListCount
DrvNum = DrvNum + 1
drvName = Chr(DrvNum) + ":\"
DrvType = GetDriveType(drvName)
Select Case GetDriveType(drvName)
Case 0
Me.Print "不明 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 2
Me.Print "软驱 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 3
Me.Print "硬盘 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 4
Me.Print "网络盘 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 5
Me.Print "光驱 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 6
Me.Print "RamDisk " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
End Select
Next i
End Sub
注释:申明API函数
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Sub Form_Load()
注释:声明变量
Dim DrvNum As Single
Dim drvName As String
Dim DrvType As Integer
Dim i As Integer
Me.AutoRedraw = True
Drive1.Visible = False
注释:获取所有常规磁盘信息——
DrvNum = Asc("a") - 1
For i = 0 To Drive1.ListCount
DrvNum = DrvNum + 1
drvName = Chr(DrvNum) + ":\"
DrvType = GetDriveType(drvName)
Select Case GetDriveType(drvName)
Case 0
Me.Print "不明 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 2
Me.Print "软驱 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 3
Me.Print "硬盘 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 4
Me.Print "网络盘 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 5
Me.Print "光驱 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 6
Me.Print "RamDisk " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
End Select
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询