You may not know what the hard disk partition information should include, but if you have been partition of the hard disk, you may have some knowledge about it. Here we will introduce you to a hard disk partition information written in VB. Program . In this program, it will tell you in detail: the total capacity of your hard disk, the total capacity of each partition, the remaining available capacity, and the number of hard disk partition tables (that is, FAT32 or fat16 ), each partition is several bytes ...... How is it? Complete and detailed enough! Okay. Let's take a look:
Preparations: create two new labels (label1 and label2) and one command1 command button on form1. Enter the following Code :
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 , Lw.ctorspercluster As Long , Lpbytespersector As Long , Lpnumberoffreeclusters As Long , Lpttoalnumberofclusters As Long ) As Long
Private Const Drive_fixed = 3
Private Sub Form_load () ' Set Initialization
Command1.caption = " Test Hard Disk "
Form1.caption = " Test hard drive program "
Label1.wordwrap = True
Label1.caption = ""
Label2.wordwrap = True
Label2.caption = ""
End sub
Private Sub Commandmediaclick ()
Dim Drivenum As Integer
Dim Tempdrive As String
Dim X As Long
For Drivenum = 97 To 122 Step 1 ' Detect from A-Z (drive letter)
Tempdrive = Getdrivetype ( CHR $ (Drivenum) & " :\ " )
Select Case Tempdrive ' If it is 3, it indicates a hard disk. test how many disks you have
Case 3
X = Getdiskspace ( CHR $ (Drivenum )) ' Call subroutine
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 ' Computing in several regions
Drive = Left $ ( Trim $ (Drivepath ), 1 ) & " :\ "
Check = Getdiskfreespace (drive, sectorspercluster, bytespersector, numberoffreeclusters, totalclusters)
If Check <> 0 Then
Diskspace = Sectorspercluster * Bytespersector * Numberoffreeclusters
' This is the formula for calculating the remaining space of a partitioned disk.
Diskspace = Format $ (diskspace, " ###,### " ) ' Display in the specified format, for example, 732,324,231
Disktotal = Sectorspercluster * Bytespersector * Totalclusters
' This is a formula for calculating the total disk capacity of a partition.
Disktotal = Format $ (disktotal, " ###,### " )
Alldisktotal = Alldisktotal + Disktotal ' Total capacity of the entire hard disk
Label1.caption = " Your total disk capacity is: " & Format $ (alldisktotal, " ###,### " ) & " Bytes, namely: " & Left $ (Alldisktotal, 1 ) & " . " & Mid $ (Alldisktotal, 2 , 1 ) & " G, total points " & Num & " , Where: "
Label2.caption = Label2.caption & Ucase $ (Drivepath) & " The total disk capacity is: " & Disktotal & " Bytes " & " The remaining disk space is: " & Diskspace & " Bytes, the disk is fat " & Sectorspercluster & " , Each partition is: " & Bytespersector & " Bytes. " & Vbcrlf & Vbcrlf
End If
End Function
OK! If you want to run it now, are you satisfied with it?
Note: The above programs have been debugged in Windows 98 and VB6.0 Enterprise Edition. (Shanghai Ji Zhao Jun)