//for WinNT/2000/XP<br>function GetClusterSize:Integer;<br>var<br> Buf:array[0..512] of byte;<br> hDeviceHandle:integer;<br>begin<br> Result:=-1;<br> hDeviceHandle := CreateFile('//./C:', GENERIC_READ, //C盘<br> FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING,0, 0);<br> if (hDeviceHandle <> INVALID_HANDLE_VALUE) then<br> begin<br> FileSeek(hDevicehandle, 0, 0);<br> FileRead(hDevicehandle, Buf, 512);<br> Result:=Buf[13]*512;<br> closehandle(hDeviceHandle);<br> end;<br>end;<br><br><br><br>//for windows9x<br>procedure TForm1.Button1Click(Sender: TObject);<br>const<br> drive=3; //c盘<br>type<br> TDiskIO=packed Record<br> dwStartSector:longint;<br> wSectors :smallint;<br> lpBuffer
char;<br> end;<br> P32Regs = ^T32Regs; //32位寄存器结构<br> T32Regs = record<br> EBX: Longint;<br> EDX: Longint;<br> ECX: Longint;<br> EAX: Longint;<br> EDI: Longint;<br> ESI: Longint;<br> Flags: Longint;<br> end;<br><br>var<br> cb
WORD;<br> str:string;<br> i:integer;<br> boot:array[0..512-1]of byte;<br> buffer:TDiskio;<br> hDeviceHandle:THandle;<br> reg:T32Regs;<br>begin<br> hDeviceHandle:=CreateFile('//./VWIN32',0,0, nil,0, FILE_FLAG_DELETE_ON_CLOSE, 0);<br> if(hDeviceHandle<>INVALID_HANDLE_VALUE) then<br> begin<br> buffer.dwStartSector:=0;<br> buffer.wSectors:=1;<br> buffer.lpBuffer:=@boot;<br> reg.EAX:=$7305;<br> reg.EBX:=Integer(@buffer);<br> reg.ECX:=-1;<br> reg.EDX:=drive;//1-A 2-b 3-c<br> reg.ESI:=0;//读<br> reg.Flags:=0;<br> DeviceIoControl(hDeviceHandle,6,@reg,sizeof(reg),@reg,sizeof(reg),cb,nil);<br> if ((reg.Flags and 1)=1) then<br> raise exception.createfmt('错误代码:%.2x',[reg.EAX and $FFFF]);<br> end;<br> ShowMessage('簇大小:'+IntToStr(boot[13]*512));<br>end;<br>