如何修改硬盘的容量?
Option ExplicitPrivate Type LARGE_INTEGERlowpart As Longhighpart As LongEnd TypePrivate Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As L...全部
Option ExplicitPrivate Type LARGE_INTEGERlowpart As Longhighpart As LongEnd TypePrivate Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As LongPrivate Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" _(ByVal lpRootPathName As String, lpFreeBytesAvailableToCaller As LARGE_INTEGER, _lpTotalNumberOfBytes As LARGE_INTEGER, lpTotalNumberOfFreeBytes _As LARGE_INTEGER) As LongPrivate Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As LongPrivate Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As LongPrivate Sub Command1_Click()'用GetDiskFreeSpaceEx得到正确的容量Dim lngFreeCaller As LARGE_INTEGERDim lngTotal As LARGE_INTEGERDim lngTotalFree As LARGE_INTEGERDim sngSize#Dim ctlNew As ControlDim t As Double, i As IntegerSet ctlNew = Me。
Controls。Add("VB。drivelistbox", "cmdNew", Me)With ctlNewFor i = 0 To 。ListCount - 1 '枚举所有盘符If GetDriveType(。
List(i)) = 3 Then '如果是硬盘盘符GetDiskFreeSpaceEx 。List(i), lngFreeCaller, lngTotal, lngTotalFree '取得该盘容量t = t + GetSize(lngTotal)End IfNextEnd WithControls。
Remove ctlNew'以下用来显示出分区总容量(以G为单位)MsgBox "硬盘容量是:" & t / 2 ^ 30 '注意:可能有误差End SubPrivate Function GetSize(lngSize As LARGE_INTEGER) As Single'用来从LARGE_INTEGER型变量中换算出实际的大小With lngSizeIf 。
highpart < 0 ThenGetSize = (2 ^ 32 - 1 - 。highpart) * (2 ^ 32 - 1)ElseGetSize = 。highpart * (2 ^ 32 - 1)End IfIf 。
lowpart < 0 ThenGetSize = GetSize + (2 ^ 32 - 1 - 。lowpart)ElseGetSize = GetSize + 。lowpartEnd IfEnd WithEnd FunctionPrivate Sub Drive1_Change()Drive1。
ListEnd Sub
。收起