-
vb教程之VB6编程中如何获取硬盘分区信息
也许你并不了解硬盘分区信息应该包括些什么,但如果你曾经对硬盘分过区,你或许对此有所了解,在此为各位介绍一个用VB编写的获取硬盘分区信息的程序。在这个程序中,它将详细地告诉你:你的硬盘总容量、分过几个区、每个区的总容量、及现在剩余的可用容量、硬盘分区表为几位(即是FAT32还是FAT16),每个分区是几个字节……怎么样?够完整详细了吧!好的,就让我们一起来看一下吧:
首先做准备工作:在FORM1上新建二个LABEL(LABEL1和LABEL2)一个COMMAND1命令按钮。然后输入以下代码:
Private Declare Function GetDriveType Lib
kernel32“Alias "GetDriveTypeA(ByVal nDrive As String) As Long
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 Const DRIVE_FIXED = 3
Private Sub Form_Load() ‘作初始化设置
COMMAND1.Caption = “测试硬盘"
Form1.Caption = “测试硬盘程序"
Label1.WordWrap = True
Label1.Caption = “"
Label2.WordWrap = True
Label2.Caption = “"
End Sub
Private Sub COMMAND1_Click()
Dim DriveNum As Integer
Dim TempDrive As String
Dim X As Long
For DriveNum = 97 To 122 Step 1 ‘检测从A-Z(盘符)
TempDrive = GetDriveType(Chr(DriveNum) & “:\")
Select Case TempDrive ‘如是3则表示是硬盘,测试你有几个盘
Case 3: X = GetDiskSpace(Chr(DriveNum)) ‘调用子程序
End Select
Next DriveNum
End Sub
Public Function GetDiskSpace(DrivePath As String)
Dim Drive As String
Dim SectorsPerCluster As Long
Dim BytesPerSector As Long
Dim NumberOfFreeClusters As Long
Dim TotalClusters As Long
Dim Check As Integer
Dim DiskSpace
Dim diskTotal
Static AllDiskTotal As Long
Static NUM As Integer
NUM = NUM + 1 ‘分几个区的计算
Drive = Left(Trim(DrivePath), 1) & “:\"
Check = GetDiskFreeSpace(Drive, SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalClusters)
If Check <> 0 Then
DiskSpace = SectorsPerCluster * BytesPerSector * NumberOfFreeClusters
‘这是一个分区磁盘剩余空间的计算公式
DiskSpace = Format$(DiskSpace, “###,###") ‘以规定格式显示,如732,324,231
diskTotal = SectorsPerCluster * BytesPerSector * TotalClusters
‘这是一个分区磁盘总容量的计算公式
diskTotal = Format$(diskTotal, “###,###")
AllDiskTotal = AllDiskTotal + diskTotal ‘整个硬盘的总容量
Label1.Caption =“你的硬盘总容量为:” & Format$(AllDiskTotal,“###,###") &个字节,即:” & Left(AllDiskTotal, 1) & . & Mid(AllDiskTotal, 2, 1) &“G,一共分了”& NUM &“个区,其中:"
Label2.Caption = Label2.Caption & UCase(DrivePath) & “盘的整个容量为:" & diskTotal &“个字节" & ",其剩余磁盘空间为:“& DiskSpace & " 个字节,磁盘已FAT“& SectorsPerCluster & ",每个分区为:“& BytesPerSector & "个字节。“& vbCrLf & vbCrLf”
End If
End Function
OK!现在你运行一下,你是否满意它?
注:以上程序在中文WINDOWS98,中文VB6.0企业版中调试通过。
首先做准备工作:在FORM1上新建二个LABEL(LABEL1和LABEL2)一个COMMAND1命令按钮。然后输入以下代码:
Private Declare Function GetDriveType Lib
kernel32“Alias "GetDriveTypeA(ByVal nDrive As String) As Long
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 Const DRIVE_FIXED = 3
Private Sub Form_Load() ‘作初始化设置
COMMAND1.Caption = “测试硬盘"
Form1.Caption = “测试硬盘程序"
Label1.WordWrap = True
Label1.Caption = “"
Label2.WordWrap = True
Label2.Caption = “"
End Sub
Private Sub COMMAND1_Click()
Dim DriveNum As Integer
Dim TempDrive As String
Dim X As Long
For DriveNum = 97 To 122 Step 1 ‘检测从A-Z(盘符)
TempDrive = GetDriveType(Chr(DriveNum) & “:\")
Select Case TempDrive ‘如是3则表示是硬盘,测试你有几个盘
Case 3: X = GetDiskSpace(Chr(DriveNum)) ‘调用子程序
End Select
Next DriveNum
End Sub
Public Function GetDiskSpace(DrivePath As String)
Dim Drive As String
Dim SectorsPerCluster As Long
Dim BytesPerSector As Long
Dim NumberOfFreeClusters As Long
Dim TotalClusters As Long
Dim Check As Integer
Dim DiskSpace
Dim diskTotal
Static AllDiskTotal As Long
Static NUM As Integer
NUM = NUM + 1 ‘分几个区的计算
Drive = Left(Trim(DrivePath), 1) & “:\"
Check = GetDiskFreeSpace(Drive, SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalClusters)
If Check <> 0 Then
DiskSpace = SectorsPerCluster * BytesPerSector * NumberOfFreeClusters
‘这是一个分区磁盘剩余空间的计算公式
DiskSpace = Format$(DiskSpace, “###,###") ‘以规定格式显示,如732,324,231
diskTotal = SectorsPerCluster * BytesPerSector * TotalClusters
‘这是一个分区磁盘总容量的计算公式
diskTotal = Format$(diskTotal, “###,###")
AllDiskTotal = AllDiskTotal + diskTotal ‘整个硬盘的总容量
Label1.Caption =“你的硬盘总容量为:” & Format$(AllDiskTotal,“###,###") &个字节,即:” & Left(AllDiskTotal, 1) & . & Mid(AllDiskTotal, 2, 1) &“G,一共分了”& NUM &“个区,其中:"
Label2.Caption = Label2.Caption & UCase(DrivePath) & “盘的整个容量为:" & diskTotal &“个字节" & ",其剩余磁盘空间为:“& DiskSpace & " 个字节,磁盘已FAT“& SectorsPerCluster & ",每个分区为:“& BytesPerSector & "个字节。“& vbCrLf & vbCrLf”
End If
End Function
OK!现在你运行一下,你是否满意它?
注:以上程序在中文WINDOWS98,中文VB6.0企业版中调试通过。
最新更新
python爬虫及其可视化
使用python爬取豆瓣电影短评评论内容
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比