VB中如何获得磁盘列表?

要求:非软盘,非光驱,是硬盘或者移动存储设备最好能加上判断是否可写入... 要求:非软盘,非光驱,是硬盘或者移动存储设备
最好能加上判断是否可写入
展开
 我来答
似水流年00
2006-09-09 · TA获得超过2073个赞
知道小有建树答主
回答量:956
采纳率:0%
帮助的人:1365万
展开全部
可以这样的解决你的问题!!一个list控件

Option Explicit

Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6

Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Private Sub Form_Load()
Dim nType As Long, S As String, sDrive As String
Dim pos As Integer

S = String(256, Chr(0))
GetLogicalDriveStrings Len(S), S

Do
pos = InStr(S, Chr(0))
sDrive = Left(S, pos - 1)
If Len(sDrive) = 0 Then Exit Do
S = Mid(S, pos + 1)

nType = GetDriveType(sDrive)
List1.AddItem Left(sDrive, 2) & " = " & GetDriveName(nType)
Loop Until pos <= 0

End Sub

Function GetDriveName(ByVal nType As Long)
Select Case nType
Case 1
GetDriveName = "目录不存在"
Case DRIVE_REMOVABLE
GetDriveName = "抽取式磁盘"
Case DRIVE_FIXED
GetDriveName = "硬盘"
Case DRIVE_REMOTE
GetDriveName = "远程(网络)储存装置"
Case DRIVE_CDROM
GetDriveName = "光盘驱动器"
Case DRIVE_RAMDISK
GetDriveName = "RAM Disk"
Case Else
GetDriveName = "无从判断"
End Select

End Function
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式