主题:vb如何得到分区信息(急)!
shuyoufeng
[专家分:0] 发布于 2008-07-04 16:37:00
想用VB写一个程序,上面有一个LISTBOX控件,怎么实现在LISTBOX控件里显示硬盘的所有分区(按盘符显示,一个盘符一行)和容量,通过选择某一个盘然后在选择的盘中安装指定的文件(如:在选择的分区里安装程序等)。请哪位高手帮忙写一下教程,在此谢谢拉!
回复列表 (共3个回复)
沙发
一江秋水 [专家分:9680] 发布于 2008-07-05 12:01:00
我以前写的一段代码,你根据情况修改一下应该可以的
Option Explicit
Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long
Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Private Sub Command1_Click()
Dim FSO, Drv, Drvs, Drive As String, sReturn As String, NUM As Integer
Dim SectorsPerCluster As Long '每簇扇区数
Dim BytesPerSector As Long '每扇区字节数
Dim NumberOfFreeClusters As Long '磁盘剩余簇数
Dim TotalClusters As Long '磁盘总簇数
Dim AllDiskTotal As Double '磁盘总容量
Dim ST As String
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Drvs = FSO.Drives
For Each Drv In Drvs
If Drv.IsReady And Drv.DriveType = 2 Then '如果是硬盘并且可用
NUM = NUM + 1: Drive = Drv.DriveLetter & ":\"
ST = Drv.DriveLetter & " 盘:"
ST = ST & vbCrLf & "容量(MB):" & Format(Drv.totalsize / 1024 / 1024, "###,###")
ST = ST & vbCrLf & "可用空间(MB):" & Format(Drv.freespace / 1024 / 1024, "###,###")
ST = ST & vbCrLf & "巻标:" & Drv.VolumeName
ST = ST & vbCrLf & "分区序列号:" & Drv.SerialNumber
ST = ST & vbCrLf & "文件系统类型:" & Drv.FileSystem
AllDiskTotal = AllDiskTotal + Drv.totalsize / 1024
If GetDiskFreeSpace(Drive, SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalClusters) <> 0 Then
ST = ST & vbCrLf & "每簇扇区数:" & SectorsPerCluster
ST = ST & vbCrLf & "每扇区字节:" & BytesPerSector
End If
sReturn = sReturn & vbCrLf & ST & vbCrLf
End If
Next
Set FSO = Nothing
ST = "总容量(G):" & AllDiskTotal \ 1000000 & vbCrLf & "分区数:" & NUM & vbCrLf & sReturn
MsgBox ST
End Sub
板凳
凡尘 [专家分:9680] 发布于 2008-07-08 15:02:00
有个dirvelist控件吧?
3 楼
guoyong_cy [专家分:3050] 发布于 2008-07-11 02:23:00
一看就是个初学者问题,本来很容易解决的
1楼的答案也太难为人家了吧!
我来回复