Drives - formatando baixo nivel |
Top Previous Next |
// formatar disquete procedure LowLevelFormat(Progress: TProgressBar); var Disk : THandle; Buffer : array [1..512] of Byte; WroteOK : Boolean; BufWrote: DWORD; begin Disk := CreateFile('\\.\A:',GENERIC_WRITE,FILE_SHARE_READ,nil,OPEN_EXISTING,0,0); if Disk = 0 then begin ShowMessage('Error - Could not open device.'); Exit; end;
FillChar(Buffer,SizeOf(Buffer),$00); WroteOK := True; BufWrote := 1;
Progress.Tag := 0; while (WroteOK = True) and (BufWrote <> 0) do begin WroteOK := WriteFile(Disk,Buffer,SizeOf(Buffer),BufWrote,nil);
Progress.Tag := Progress.Tag + 1;
if Progress.Tag mod 25 = 0 then begin Progress.StepIt; Application.ProcessMessages; end; end; CloseHandle(Disk); end;
// bug: perde a FAT.... mas formata!
------------------------------ OTHER DICA: ---------------------------- Use the raw API DeviceIOControl, passing IOCTL_DISK_FORMAT_TRACKS as second parameter. Download the JwaWin32 API translated from Jedi for the constants and structs useds, and search in Windows SDK for how use this. |