给你做个参考,在Win32x下完整的硬盘信息读取控件。
unit DiskInfo;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type string1 = string[1];
type string30 = string[30];
type
TDiskInfo = class(TComponent)
private
FSectorsPerCluster
WORD; // holds the sectors per cluster
FBytesPerSector
WORD; // holds the bytes per sector
FFreeClusters
WORD; // holds the number of free clusters
FClusters
WORD; // holds the total number of disk clusters
FDiskFreeSpace
WORD; // holds the total free space
FTotalDiskSpace
WORD; // holds total disk capacity
FDrive :string1;
FDriveType :string30;
FVolumeName :string;
FSerialNumber :string;
FFileSystemType :string;
function GetDriveTyp :string30;
procedure SetDrive(value:string1);
protected
{ Protected declarations }
public
constructor create(AOwner:TComponent); override;
published
{ Published declarations }
property Drive :string1 read FDrive write setdrive;
property SectorsPerCluster
WORD read FSectorsPerCluster;
property BytesPerSector
WORD read FBytesPerSector;
property FreeClusters
WORD read FFreeClusters;
property Clusters
WORD read FClusters;
property DiskFreeSpace
WORD read FDiskFreeSpace;
property TotalDiskSpace
WORD read FTotalDiskSpace;
property DriveType :string30 read GetDriveTyp;
property VolumeName :string read FVolumeName;
property SerialNumber :string read FSerialNumber;
property FileSystemType :string read FFileSystemType;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Smart', [TDiskInfo]);
end;
constructor TDiskInfo.create(AOwner:TComponent);
begin
inherited create(AOwner);
setdrive('C');
end;
procedure TDiskInfo.SetDrive(value:string1);
var fulldrive :string[3];
tmp_drive :array[0..2] of char;
Tmp_SectorsPerCluster, // holds the sectors per cluster
Tmp_BytesPerSector, // holds the bytes per sector
Tmp_FreeClusters, // holds the number of free clusters
Tmp_Clusters
WORD; // holds the total number of disk clusters
VolName :array[0..255] of Char; // holds the volume name
SerialNumber
WORD; // holds the serial number
MaxCLength
WORD; // holds the maximum file component length
FileSysFlag
WORD; // holds file system flags
FileSysName :array[0..255] of Char; // holds the name of the file system
begin
fdrive:=value;
fulldrive:=value + ':/';
strpcopy(tmp_drive,fulldrive);
if GetDiskFreeSpace(tmp_drive,Tmp_SectorsPerCluster,Tmp_BytesPerSector,
Tmp_FreeClusters,Tmp_Clusters) then
begin
FSectorsPerCluster:=Tmp_SectorsPerCluster;
FBytesPerSector:=Tmp_BytesPerSector;
FFreeClusters:=Tmp_FreeClusters;
FClusters:=Tmp_Clusters;
FDiskFreeSpace:=Tmp_FreeClusters*Tmp_BytesPerSector*Tmp_SectorsPerCluster;
FTotalDiskSpace:=Tmp_Clusters*Tmp_BytesPerSector*Tmp_SectorsPerCluster;
end;
{retrieve the volumn information}
GetVolumeInformation(tmp_drive, VolName, 255, @SerialNumber, MaxCLength,
FileSysFlag, FileSysName, 255);
FVolumeName:=VolName;
FSerialNumber:=IntToHex(SerialNumber,8);
FFileSystemType:=FileSysName;
end;
function TDiskInfo.GetDriveTyp :string30;
var fulldrive :string[3];
tmp_drive :array[0..2] of char;
begin
fulldrive:=fdrive + ':/';
strpcopy(tmp_drive,fulldrive);
{retrieve the drive type}
case GetDriveType(tmp_drive) of
DRIVE_UNKNOWN :result:='No Type Information';
DRIVE_NO_ROOT_DIR :result:='Root Directory does not exist';
DRIVE_REMOVABLE :result:='Removable';
DRIVE_FIXED :result:='Fixed';
DRIVE_REMOTE :result:='Remote';
DRIVE_CDROM :result:='CDROM';
DRIVE_RAMDISK :result:='RamDisk';
end;
end;
end.