vb怎么获取某个磁盘的名称? 50
展开全部
转:
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
追问
已经找到办法啦,也就两句代码的事。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询