用delphi如何实现运行一个.exe文件中删除自己?

akuan 2000-08-15 05:57:00
用delphi如何实现运行一个.exe文件的过程中删除自己,以后不再运行?请指点.
...全文
1073 43 打赏 收藏 转发到动态 举报
写回复
用AI写文章
43 条回复
切换为时间正序
请发表友善的回复…
发表回复
akuan 2001-03-24
  • 打赏
  • 举报
回复
我觉得都没有达到最好的效果.
dbpower 2001-01-16
  • 打赏
  • 举报
回复
a common trick to make a program self-destruct is to have it write a tiny
batch file, and, as the very last thing it does before closing, starting
this batch file with a
winexec(batchfilename, SW_HIDE );
The batch deletes the program and then can delete itself. The last line is a
del %0
and it is *not* terminated with a carriage return/line feed pair.

lixiaolei 2001-01-16
  • 打赏
  • 举报
回复
关注!
Ring0下怎么删除文件?
icecream 2001-01-16
  • 打赏
  • 举报
回复
给你一份抄来的程序。
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure DeleteMe;
var
BatchFile: TextFile;
BatchFileName: string;
ProcessInfo: TProcessInformation;
StartUpInfo: TStartupInfo;
begin
BatchFileName := ExtractFilePath(ParamStr(0)) + '_deleteme.bat';

AssignFile(BatchFile, BatchFileName);
Rewrite(BatchFile);

Writeln(BatchFile, ':try');
Writeln(BatchFile, 'del "' + ParamStr(0) + '"');
Writeln(BatchFile,
'if exist "' + ParamStr(0) + '"' + ' goto try');
Writeln(BatchFile, 'del %0');
CloseFile(BatchFile);

FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);
StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
StartUpInfo.wShowWindow := SW_HIDE;

if CreateProcess(nil, PChar(BatchFileName), nil, nil,
False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo,
ProcessInfo) then
begin
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
DeleteMe;
close;
end;

end.
dbpower 2001-01-15
  • 打赏
  • 举报
回复
akuan也真逗!还亏whoo兄仔细!是akuan消失了?还是真要做长线?
whoo 2001-01-06
  • 打赏
  • 举报
回复
MoveFileEx.不过95好像不能用,但是95好像不能保证打开的文件不被DeleteFile删除.
--------"好像"的意思是有一笨<<Windows高级编程>>这么说过.不过我也将信将疑.
gameboy999 2001-01-06
  • 打赏
  • 举报
回复
DeleteFile!就是这个!
gameboy999 2001-01-06
  • 打赏
  • 举报
回复
DeleteFile!就是这个!
BCB 2001-01-04
  • 打赏
  • 举报
回复
高手尚未出世!

Kingron 2001-01-04
  • 打赏
  • 举报
回复
呵呵,去年8月份的贴子?听起来很遥远,其实就那么几个月的时间嘛。
whoo 2001-01-04
  • 打赏
  • 举报
回复
好像有一个带Ex的删除(拷贝)文件的Api,可以指定一个参数,告诉他如果现在无法删除,将自动在下次启动时删除.安装程序时有时候弹出的对话框"安装程序需要重新启动后才能继续进行."就使用的这个Api.

刚才看见这个标题就觉得有点眼熟,倒也没怎么留意.无意中看了一眼日期,哇~~~~~~~~,去年8月份的贴子.akuan老兄 放的线可真够长的!!!!那个时候我在CSDN还没有账号呢,没事只能看<程序员大本营>!
想不到这个贴子的年龄比我在CSDN的年龄还长.
dbpower 2001-01-04
  • 打赏
  • 举报
回复
kasteboy的说法和我以前的做法一样;但NT有一定问题!
在form1.close中加入如下代码即可实现删除文件本身
AssignFile(F, 'delself.bat');
Rewrite(F);//f为文本文件
WriteLn(F,'del'+ExtractFileName(Application.ExeName));
WriteLn(F,'del %0');
CloseFile(F);
WinExec('delself.bat',SW_HIDE);

如果要求该程序在运行时删除!那就需要更麻烦的处理了!


akuan 2001-01-01
  • 打赏
  • 举报
回复
高手快出招!!!
eastroc 2000-12-29
  • 打赏
  • 举报
回复
Kingron说的不错,如果Exe文件要删除运行中的自己,那是很麻烦的。
这种技术像“冰河”就是这样的。要知道一些Windows的隐藏秘密。那该死的Bill。
如果是要以后删除的话,上面的朋友是八仙过海,各显神通呀!
关注“Exe文件要删除运行中的自己”这个问题,有谁做过,可否道来!期待!
BCB 2000-12-29
  • 打赏
  • 举报
回复
在RING0下,能调用什么特权子程序?
若调API又回到RING3,算白搭!
调BIOS功能又太弱,有啥用?
其他呢?高手快出手,我给分!!!



BCB 2000-12-29
  • 打赏
  • 举报
回复
特权RING0下能不能删,
有没有高手试过?!
wenzm 2000-12-29
  • 打赏
  • 举报
回复
转贴:
How Can A Exe File Kill himself?
a common trick to make a program self-destruct is to have it write a tiny
batch file, and, as the very last thing it does before closing, starting
this batch file with a
winexec(batchfilename, SW_HIDE );
The batch deletes the program and then can delete itself. The last line is a

del %0

and it is *not* terminated with a carriage return/line feed pair.
lixiaolei 2000-12-27
  • 打赏
  • 举报
回复
方法是可行的,但过于勉强!,有更好的方法?
victorchen_2000 2000-12-27
  • 打赏
  • 举报
回复
NT为什么行不通啊?难道NT不支持批处理吗?谁说的?
oldsword 2000-12-26
  • 打赏
  • 举报
回复
以上的方法都是用批处理,在NT下恐怕是行不通罢!!!
加载更多回复(23)

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧