VB中如何获得磁盘列表?

来源:百度知道 编辑:UC知道 时间:2024/05/08 01:45:20
要求:非软盘,非光驱,是硬盘或者移动存储设备
最好能加上判断是否可写入

可以这样的解决你的问题!!一个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(sD