也許你并不了解硬盤(pán)分區(qū)信息應(yīng)該包括些什么,但如果你曾經(jīng)對(duì)硬盤(pán)分過(guò)區(qū),你或許對(duì)此有所了解,在此為各位介紹一個(gè)用VB編寫(xiě)的獲取硬盤(pán)分區(qū)信息的程序。在這個(gè)程序中,它將詳細(xì)地告訴你:你的硬盤(pán)總?cè)萘俊⒎诌^(guò)幾個(gè)區(qū)、每個(gè)區(qū)的總?cè)萘俊⒓艾F(xiàn)在剩余的可用容量、硬盤(pán)分區(qū)表為幾位(即是FAT32還是FAT16),每個(gè)分區(qū)是幾個(gè)字節(jié)……怎么樣?夠完整詳細(xì)了吧!好的,就讓我們一起來(lái)看一下吧: 首先做準(zhǔn)備工作:在FORM1上新建二個(gè)LABEL(LABEL1和LABEL2)一個(gè)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() ‘作初始化設(shè)置 COMMAND1.Caption = “測(cè)試硬盤(pán)" Form1.Caption = “測(cè)試硬盤(pán)程序" 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 ‘檢測(cè)從A-Z(盤(pán)符) TempDrive = GetDriveType(Chr(DriveNum) & “:\") Select Case TempDrive ‘如是3則表示是硬盤(pán),測(cè)試你有幾個(gè)盤(pán) Case 3: X = GetDiskSpace(Chr(DriveNum)) ‘調(diào)用子程序 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 ‘分幾個(gè)區(qū)的計(jì)算 Drive = Left(Trim(DrivePath), 1) & “:\" Check = GetDiskFreeSpace(Drive, SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalClusters) If Check <> 0 Then DiskSpace = SectorsPerCluster * BytesPerSector * NumberOfFreeClusters ‘這是一個(gè)分區(qū)磁盤(pán)剩余空間的計(jì)算公式 DiskSpace = Format$(DiskSpace, “###,###") ‘以規(guī)定格式顯示,如732,324,231 diskTotal = SectorsPerCluster * BytesPerSector * TotalClusters ‘這是一個(gè)分區(qū)磁盤(pán)總?cè)萘康挠?jì)算公式 diskTotal = Format$(diskTotal, “###,###") AllDiskTotal = AllDiskTotal + diskTotal ‘整個(gè)硬盤(pán)的總?cè)萘?br> Label1.Caption =“你的硬盤(pán)總?cè)萘繛?” & Format$(AllDiskTotal,“###,###") &個(gè)字節(jié),即:” & Left(AllDiskTotal, 1) & . & Mid(AllDiskTotal, 2, 1) &“G,一共分了”& NUM &“個(gè)區(qū),其中:" Label2.Caption = Label2.Caption & UCase(DrivePath) & “盤(pán)的整個(gè)容量為:" & diskTotal &“個(gè)字節(jié)" & ",其剩余磁盤(pán)空間為:“& DiskSpace & " 個(gè)字節(jié),磁盤(pán)已FAT“& SectorsPerCluster & ",每個(gè)分區(qū)為:“& BytesPerSector & "個(gè)字節(jié)。“& vbCrLf & vbCrLf” End If End Function OK!現(xiàn)在你運(yùn)行一下,你是否滿(mǎn)意它? 注:以上程序在中文WINDOWS98,中文VB6.0企業(yè)版中調(diào)試通過(guò)。
|