问题来源:http://www.cnblogs.com/del/archive/2008/08/12/1266368.html#2028808

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;

相关文章:

  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2022-02-16
  • 2021-05-25
  • 2021-11-15
  • 2021-11-30
  • 2021-06-17
猜你喜欢
  • 2022-12-23
  • 2021-08-21
  • 2021-12-21
  • 2021-09-19
  • 2022-01-10
  • 2021-07-02
  • 2022-02-04
相关资源
相似解决方案