VB6編程中如何獲取硬盤分區信息

發表于:2007-07-14來源:作者:點擊數: 標簽:
也許你并不了解硬盤分區信息應該包括些什么,但如果你曾經對硬盤分過區,你或許對此有所了解,在此為各位介紹一個用 VB 編寫的獲取硬盤分區信息的程序。在這個程序中,它將詳細地告訴你:你的硬盤總容量、分過幾個區、每個區的總容量、及現在剩余的可用容量
也許你并不了解硬盤分區信息應該包括些什么,但如果你曾經對硬盤分過區,你或許對此有所了解,在此為各位介紹一個用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企業版中調試通過。

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97