/其中VolumeName,VolumeSerialNumber,PartitionType,TotalSpace,TotalFreeSpace 为 //返回参数,包括分区的各种信息 Function GetHardDiskPartitionInfo(const DriveLetter:Char; var VolumeName,VolumeSerialNumber,PartitionType:string; var TotalSpace,TotalFreeSpace:string): string; var NotUsed: DWORD; VolumeFlags: DWORD; VolumeInfo: array[0..MAX_PATH] of Char; VSNumber: DWORD; PType: array[0..32] of Char; VName:array[0..32] of Char; FreeS,TotalS:Int64; TotalF:Int64; begin if not GetVolumeInformation(PChar(DriveLetter + ':\'), @VName, SizeOf(VolumeInfo), @VSNumber, NotUsed, VolumeFlags, PType, 32) then result:='卷信息未能xx返回'#13#10; VolumeName:=strpas(VName); VolumeSerialNumber:=InttoHex(VSNumber,8); PartitionType:=StrPas(PType); if not GetDiskFreeSpaceEx(PChar(DriveLetter + ':\'),FreeS,TotalS,@TotalF) then result:=result+'获取卷空间大小失败'; TotalSpace:=FloatToStr(Round(TotalS / 1024 / 1024 /1024 * 100) / 100); TotalFreeSpace:=FloatToStr(Round(TotalF / 1024 / 1024 /1024 * 100) / 100); end; //函数很简单,一看就明白 注意:根据MSDN的说明,如果分区大于2G一定要用 GetDiskFreeSpaceEx //以下是调用实例 procedure TForm1.Button1Click(Sender: TObject); var VName,VSNumber,PType:string; TotalS,TotalF:string; begin GetHardDiskPartitionInfo('c',VName,VSNumber,PType, TotalS,TotalF); memo1.Lines.Add('卷标:'+VName); memo1.Lines.Add('卷序列号:'+VSNumber); memo1.Lines.Add('分区类型:'+PType); memo1.Lines.Add('分区总空间大小:'+TotalS+' G'); memo1.Lines.Add('分区剩余空间大小:'+TotalF+' G'); end; |