function GetDiskSerial(Drv:string):string;
function DecToHex(DecVal:LongInt):String;
const
HexDigits : Array[0..15] of Char = '0123456789ABCDEF';
var
Temp : String;
begin
Temp := '';
Temp := Temp + HexDigits[(DecVal shr 28) and $F];
Temp := Temp + HexDigits[(DecVal shr 24) and $F];
Temp := Temp + HexDigits[(DecVal shr 20) and $F];
Temp := Temp + HexDigits[(DecVal shr 16) and $F];
Temp := Temp + HexDigits[(DecVal shr 12) and $F];
Temp := Temp + HexDigits[(DecVal shr 8) and $F];
Temp := Temp + HexDigits[(DecVal shr 4) and $F];
Temp := Temp + HexDigits[DecVal and $F];
Result := Temp;
end;
var
VolumeLabel, FileSystem: Array[0..$FF] of Char;
SerialNumber, DW, SysFlags: DWord;
begin
if (Drv >= 'A') and (Drv <= 'Z') then
GetVolumeInformation(PChar(Drv+':/'),VolumeLabel,SizeOf(VolumeLabel),
@SerialNumber, DW, SysFlags,
FileSystem, SizeOf(FileSystem))
else
SerialNumber:=12345678;
Result:=DecToHex(SerialNumber);
end;
// 用法
procedure TForm1.Button2Click(Sender: TObject);
begin
form1.Caption:=GetDiskSerial('c');
// 取C盘的序列号
end;