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;

相关阅读 >>

Delphi 从摄像头获取照片并转换为特定的格式

Delphi 设置系统静音取消系统静音

Delphi 对提交参数编码

Delphi读写xml的技巧

Delphi 2010 fastmm 内存泄露使用方法

Delphi自动提交网页表单和获取框架网页源码

剪贴板单元 clipboards.pas

Delphi 的 tstringbuilder 可以完美实现jave ,c#的tstringbuilder功能

Delphi 用ini记录combobox的itemindex

Delphi中dbgrid控件数据库点击某列按序排列

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...