GARANTIR DESCONTO

Fórum Renomear um exe em tempo de execução. #218945

08/03/2004

0

Bom dia.

Sei que parece impossível, mas com estas funções consegui apagar um EXE em tempo de execução. Então eu pensei, se eu posso apagar, talvez possa renomear. Estas funções criam um bat, apagam o EXE, e depois deletam o bat.
O que eu quero é o seguinte:
Tenho dois arquivos teste.exe e teste2.exe. Qdo apagar teste.exe, eu renomeio teste2.exe para teste.exe.

function GetTmpDir: string; // Get the windows temporary directory
var
pc: PChar;
begin
pc := StrAlloc(MAX_PATH + 1);
GetTempPath(MAX_PATH, pc);
Result := string(pc);
StrDispose(pc);
end;

procedure DelExe; // procedure to delete the current program
function GetTmpFileName(ext: string): string;
var
pc: PChar;
begin
pc := StrAlloc(MAX_PATH + 1);
GetTempFileName(PChar(GetTmpDir), ´EZC´, 0, pc);
Result := string(pc);
Result := ChangeFileExt(Result, ext);
StrDispose(pc);
end;
var
batchfile: TStringList;
batchname: string;
begin
batchname := GetTmpFileName(´.bat´);
FileSetAttr(ParamStr(0), 0);
batchfile := TStringList.Create;
with batchfile do
begin
try
Add(´:Label1´);
Add(´del ´´ + ParamStr(0) + ´´´);
Add(´if Exist ´´ + ParamStr(0) + ´´ goto Label1´);
Add(´rmdir ´´ + ExtractFilePath(ParamStr(0)) + ´´´);
Add(´del ´´ + GetTmpDir + ExtractFileName(ParamStr(0)) + ´´´);
Add(´del ´ + batchname);
SaveToFile(batchname);
ChDir(GetTmpDir);
WinExec(PChar(batchname), SW_HIDE);
finally
batchfile.Free;
end;
Halt;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
DelExe;
end;


Grato pela atenção.


Turbo Drive

Turbo Drive

Responder

Posts

09/03/2004

Zumbi

ae velho... blz.

vejamos se eu entendi direito vc quer pegar o nome de um arquivo e renomea-lo para outro nome... correto!
tente o seguinte:

FUNCTION form1.renomeia_arquivo(arquivo: string): string; var arq_atual, novo_arq : string; begin arq_atual := Copy(arquivo,1,Pos(´@´, arquivo)-1); novo_arq := Copy(arquivo, Pos(´@´, arquivo)+1, length(arq_atual)); if(renameFile(arq_atual, novo_arq)) then result := ´Arquivo ´ ´+arq_atual+´ ´ renomeado para ´ ´+novo_arq+´ ´!´ else result := ´Nao foi possivel renomear o arquivo ´ ´+arq_atual+´ ´ renomeado para ´ ´+novo_arq+´ ´!´ end;


qualquer coisa estou no msn...


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar