VB中怎么用API获取磁盘的容量信息
展开全部
转:
api函数获取磁盘容量:
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" _
(ByVal lpDirectoryName As String, ByRef lpFreeBytesAvailableToCaller As Long, _
ByRef lpTotalNumberOfBytes As Long, ByRef lpTotalNumberOfFreeBytes As Long) As Long
Private Sub btnDisk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisk.Click
Dim BytesFreeToCalller As Long, TotalBytes As Long
Dim TotalFreeBytes As Long, TotalBytesUsed As Long
Dim strResult As String
Const RootPathName = "C:\"
Call GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
strResult = " Drive " & "C:\" & vbCrLf
strResult += "磁盘容量(MB):" & Format(CDbl((TotalBytes / 1024) / 1024), "###,###,##0.00") & vbCrLf
strResult += "可用空间(MB):" & Format(CDbl((TotalFreeBytes / 1024) / 1024), "###,###,##0.00") & vbCrLf
strResult += "已用空间(MB):" & Format(CDbl(((TotalBytes - TotalFreeBytes) / 1024) / 1024), "###,###,##0.00") & vbCrLf
MsgBox(strResult)
End Sub
api函数获取磁盘容量:
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" _
(ByVal lpDirectoryName As String, ByRef lpFreeBytesAvailableToCaller As Long, _
ByRef lpTotalNumberOfBytes As Long, ByRef lpTotalNumberOfFreeBytes As Long) As Long
Private Sub btnDisk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisk.Click
Dim BytesFreeToCalller As Long, TotalBytes As Long
Dim TotalFreeBytes As Long, TotalBytesUsed As Long
Dim strResult As String
Const RootPathName = "C:\"
Call GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
strResult = " Drive " & "C:\" & vbCrLf
strResult += "磁盘容量(MB):" & Format(CDbl((TotalBytes / 1024) / 1024), "###,###,##0.00") & vbCrLf
strResult += "可用空间(MB):" & Format(CDbl((TotalFreeBytes / 1024) / 1024), "###,###,##0.00") & vbCrLf
strResult += "已用空间(MB):" & Format(CDbl(((TotalBytes - TotalFreeBytes) / 1024) / 1024), "###,###,##0.00") & vbCrLf
MsgBox(strResult)
End Sub
展开全部
使用getDiskFreeSpace函数
GetDiskFreeSpace
VB声明
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
说明
获取与一个磁盘的组织有关的信息,以及了解剩余空间的容量
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpRootPathName String,不包括卷名的一个磁盘根路径
lpSectorsPerCluster Long,用于装载一个簇内扇区数的变量
lpBytesPerSector Long,用于装载一个扇区内字节数的变量
lpNumberOfFreeClusters Long,用于装载磁盘上剩余簇数的变量
lpTtoalNumberOfClusters Long,用于装载磁盘上总簇数的变量
注解
在采用FAT16格式的windows95系统中,如一个驱动器(分区)的容量超过了2GB,则不应使用这个函数。此时,这个函数能识别的最大分区容量只有2GB
GetDiskFreeSpace
VB声明
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
说明
获取与一个磁盘的组织有关的信息,以及了解剩余空间的容量
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpRootPathName String,不包括卷名的一个磁盘根路径
lpSectorsPerCluster Long,用于装载一个簇内扇区数的变量
lpBytesPerSector Long,用于装载一个扇区内字节数的变量
lpNumberOfFreeClusters Long,用于装载磁盘上剩余簇数的变量
lpTtoalNumberOfClusters Long,用于装载磁盘上总簇数的变量
注解
在采用FAT16格式的windows95系统中,如一个驱动器(分区)的容量超过了2GB,则不应使用这个函数。此时,这个函数能识别的最大分区容量只有2GB
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询