Ver Mensaje Individual
  #2  
Antiguo 23-01-2007
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 24
seoane Va por buen camino
Este tema ya se trato en el foro otras veces. Pero de todas formas:

Usando un bat:
Código Delphi [-]
uses ShellApi;

procedure Borrate;
var
  Path: String;
  Buffer: array[0..MAX_PATH] of Char;
begin
  if GetShortPathName(PChar(ParamStr(0)),@Buffer, Sizeof(Buffer) -1) = 0 then
    Exit;
  Path:= String(PChar(@Buffer));
  with TStringList.Create do
  try
    Add(':BUCLE');
    Add('Del ' + Path);
    Add('if %ERRORLEVEL% NEQ 0 goto BUCLE');
    SaveToFile(ChangeFileExt(ParamStr(0),'.bat'));
    ShellExecute(0,nil,PChar(ChangeFileExt(ParamStr(0),'.bat')),nil,nil,SW_SHOW);
  finally
    Free;
  end;
end;

// Por ejmeplo, lo usamos en el evento OnClose
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Borrate;
end;

Usando MoveFileEx, retrasando el borrado hasta que el equipo se reinicie:
Código Delphi [-]
procedure Borrate;
var
  Buffer: array[0..MAX_PATH] of Char;
begin
  if GetShortPathName(PChar(ParamStr(0)),@Buffer, Sizeof(Buffer) -1) <> 0 then
    MoveFileEx(Buffer, nil, MOVEFILE_DELAY_UNTIL_REBOOT or
      MOVEFILE_REPLACE_EXISTING);
end;

Y si no te gusta ninguna de las 2, en esta pagina explican todas las formas imaginables para hacerlo.

http://www.catch22.net/tuts/selfdel.asp
Responder Con Cita