در هنگام آزمایش مراقب باشید.

const 
  
SHFMT_DRV_A = 0;
  SHFMT_DRV_B = 1;
  SHFMT_ID_DEFAULT = $FFFF;
  SHFMT_OPT_QUICKFORMAT = 0;
  SHFMT_OPT_FULLFORMAT = 1;
  SHFMT_OPT_SYSONLY = 2;
  SHFMT_ERROR = -1;
  SHFMT_CANCEL = -2;
  SHFMT_NOFORMAT = -3;

function SHFormatDrive(hWnd: HWND;
  Drive: Word;
  fmtID: Word;
  Options: Word): Longint
  stdcallexternal 'Shell32.dll' Name 'SHFormatDrive';


procedure TForm1.Button1Click(Sender: TObject);
var
  
FmtRes: Longint;
begin
  try
    
FmtRes := ShFormatDrive(Handle,
      SHFMT_DRV_A,
      SHFMT_ID_DEFAULT,
      SHFMT_OPT_QUICKFORMAT);
    case FmtRes 
of
      
SHFMT_ERROR: ShowMessage('Error formatting the drive');
      SHFMT_CANCEL: ShowMessage('User canceled formatting the drive');
      SHFMT_NOFORMAT: ShowMessage('No Format')
        
else
          
ShowMessage('Disk has been formatted!');
    end;
  
except
    
ShowMessage('Error Occured!');
  end;
end;


var
  
EMode: Word;
begin
  
EMode := SetErrorMode(SEM_FAILCRITICALERRORS);
  
// ShFormatDrive Code....
  
SetErrorMode(EMode);
end;