本文主要是介绍让程序运行后自我删除或恢复名称 - 回复 "实习新手" 的问题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
让程序运行后自我删除或恢复名称 - 回复 "实习新手" 的问题
问题来源: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;
posted on
2011-02-18 13:02
万一
阅读(3114)
评论(20)
编辑
收藏
这篇关于让程序运行后自我删除或恢复名称 - 回复 "实习新手" 的问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!