HanDs
管理员

[Delphi文章] 让程序运行后自我删除或恢复名称 



unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormDestroy(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormDestroy(Sender: TObject);
const
  batFile = 'tmp.bat';
begin
  ChDir(ExtractFilePath(Application.ExeName));
  with TStringList.Create do begin
    Add('del ' + Application.ExeName);
    Add('del ' + batFile);
    SaveToFile(batFile);
    Free;
  end;
  WinExec(batFile, SW_HIDE);
end;

end.

--------------------------------------------------------------------------------

改回应有的名称:
--------------------------------------------------------------------------------
 

procedure TForm1.FormDestroy(Sender: TObject);
const
  batFile = 'tmp.bat';
  oldName = '123.exe'; //假如这是要恢复的名称
begin
  if ExtractFileName(Application.ExeName) = oldName then Exit;
  ChDir(ExtractFilePath(Application.ExeName));
  with TStringList.Create do begin
    Add('ren ' + Application.ExeName + ' ' + oldName);
    Add('del ' + batFile);
    SaveToFile(batFile);
    Free;
  end;
  WinExec(batFile, SW_HIDE);
end;


学习中请遵守法律法规,本网站内容均来自于互联网,本网站不负担法律责任
程序 运行 自我 删除 恢复 名称
#1楼
发帖时间:2016-7-9   |   查看数:0   |   回复数:0
游客组
快速回复