emerald lake在哪儿:VB6用哪个API能获取硬盘信息的?

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/01 08:47:13
获取硬盘序列号等相关信息,请给出函数原型,最好有参数释义,谢谢

在窗体中添加一个名为Drive的DriveListBox

Option Explicit

Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
Alias "GetDiskFreeSpaceExA" _
(ByVal lpRootPathName As String, _
lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency) As Long

Dim r As Long, BytesFreeToCalller As Currency, TotalBytes As Currency
Dim TotalFreeBytes As Currency, TotalBytesUsed As Currency
Dim TNB As Double
Dim TFB As Double
Dim FreeBytes As Long
Dim DriveLetter As String
Dim DLetter As String
Dim spaceInt As Integer
Public Sub GetDiskInfo()
'
'Original sample was written by James Limm on 22/11/97,
'** E-Mail : jelsoft@btinternet.com ** using the
'GetDiskFreeSpace API Function. This revised sample
'was written by John Cunningham using the GetDiskFreeSpaceEx
'API Function. The GetDiskFreeSpaceEx has more flexibility.
'(Allows getting all disk information.
' email: johnpc@ids.net
' Web: http://users.ids.net/~johnpc
'--------------------------------------------------------

'The following code prepares the drive letter. It is
'essential that you pass the drive letter to the API
'function in the form c:\. You can not pass
'Drive1.Drive directly because often this does not
'contain the correct format ("c:\").

'copy the drive letter into the variable DriveLetter
DriveLetter = Drive1.Drive

'If there is a space on the end of DriveLetter, remove it
spaceInt = InStr(DriveLetter, " ")
If spaceInt > 0 Then DriveLetter = Left$(DriveLetter, spaceInt - 1)

'if there is not a "\" on the end of DriveLetter, add it
If Right$(DriveLetter, 1) <> "\" Then DriveLetter = DriveLetter & "\"
DLetter = Left(UCase(DriveLetter), 1)

'get the drive's disk parameters
Call GetDiskFreeSpaceEx(DriveLetter, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
'show the results, multiplying the returned
'value by 10000 to adjust for the 4 decimal
'places that the currency data type returns.
AutoRedraw = True
Cls

ForeColor = QBColor(1)
Print
Print
Print
Print
Print " Information for Drive " & DLetter
Print " ------------------------------------ "

Print

Print " Total Number Of Bytes:", Format$(TotalBytes * 10000, "###,###,###,##0") & " bytes"
Print " Total Free Bytes:", Format$(TotalFreeBytes * 10000, "###,###,###,##0") & " bytes"
Print " Free Bytes Available:", Format$(BytesFreeToCalller * 10000, "###,###,###,##0") & " bytes"

Print " Total Space Used :", Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0") & " bytes"
Print
ForeColor = QBColor(12)
TNB = TotalBytes * 10000
TFB = (TotalBytes - TotalFreeBytes) * 10000
Print " % - Drive " & DLetter & ": Disk Space Used = " & Format(TFB / TNB * 100, "###.#0") & " %"
Print " % - Drive " & DLetter & ": Disk Space Available = " & Format(100 - TFB / TNB * 100, "###.#0") & " %"
Print
Print "DriveLetter = " & DriveLetter
End Sub

Private Sub Command1_Click()
GetDiskInfo

End Sub

Private Sub Drive1_Change()
GetDiskInfo

End Sub

Private Sub Form_Load()
GetDiskInfo

End Sub