正在阅读:VB.NET下获取硬盘信息的几种方法VB.NET下获取硬盘信息的几种方法

2004-03-11 10:00 出处:CSDN 作者:lihonggen0 责任编辑:linjixiong
  1、用API函数GetDiskFreeSpaceEx获取磁盘空间

  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

  2、用FSO(文件系统对象模型)实现

  FSO对象模型包含在SCRIPTING类型库(SCRRUN.DLL)中。调用方法如下:

  在项目菜单中选择引用,在COM中选择Microsoft Scripting Runtime




察看评论详细内容 我要发表评论
作者笔名简短内容 发表时间
:

键盘也能翻页,试试“← →”键

相关文章

关注我们

最新资讯离线随时看 聊天吐槽赢奖品