program Project1;
uses
SysUtils, windows;
var f:textfile;
a:string; begin
a:=paramstr();
assignfile(f, 'delself.bat');
rewrite(f);
writeln(f, 'del ' + pchar('"'+pchar(a)+'"'));
writeln(f, 'del %0');
closefile(f);
winexec('delself.bat', sw_hide);
end.

http://blog.csdn.net/emdfans/article/details/11769483

program Project1;  //方法一
uses
Windows;
function WinExec(lpCmdline: PAnsiChar; uCmdShow: LongWord): LongWord;
stdcall; external 'kernel32.dll' name 'WinExec';
function ExtractFilePath(FileName: string): string;
begin
Result := '';
while ((Pos('/', FileName) <> ) or (Pos('/', FileName) <> )) do
begin
Result := Result + Copy(FileName, , );
Delete(FileName, , );
end;
end; procedure DeleteMe;
var
BatchFile: TextFile;
BatchFileName: string;
begin
BatchFileName := ExtractFilePath(ParamStr()) + '_deleteme.bat';
AssignFile(BatchFile, BatchFileName);
Rewrite(BatchFile);
Writeln(BatchFile, ':try');
Writeln(BatchFile, 'del "' + ParamStr() + '"');
Writeln(BatchFile,
'if exist "' + ParamStr() + '"' + ' goto try');
Writeln(BatchFile, 'del %0');
CloseFile(BatchFile);
end;
begin
DeleteMe ;
WinExec('_deleteme.bat',SW_HIDE);
end.
------------------------------------------------------------------------------
简单自删除 //方法二
var
f:textfile;
self:string;
begin
self:=paramstr();
assignfile(f,'delself.bat');
rewrite(f);
writeln(f,'del '+pchar('"'+pchar(self)+'"'));
writeln(f,'del %0');
closefile(f);
WinExec('delself.bat',sw_hide);
end;
---------------------------------------------------------------------------------
program Project2; //方法三
uses
Windows, ShellAPI, ShlObj, SysUtils2;
function Suicide: Boolean;
var
sei: TSHELLEXECUTEINFO;
szModule: PChar;
szComspec: PChar;
szParams: PChar;
begin
szModule := AllocMem(MAX_PATH);
szComspec := AllocMem(MAX_PATH);
szParams := AllocMem(MAX_PATH);
// get file path names:
if ((GetModuleFileName(,szModule,MAX_PATH)<>) and
(GetShortPathName(szModule,szModule,MAX_PATH)<>) and
(GetEnvironmentVariable('COMSPEC',szComspec,MAX_PATH)<>)) then
begin
// set command shell parameters
lstrcpy(szParams,'/c del ');
lstrcat(szParams, szModule);
// set struct members
sei.cbSize := sizeof(sei);
sei.Wnd := ;
sei.lpVerb := 'Open';
sei.lpFile := szComspec;
sei.lpParameters := szParams;
sei.lpDirectory := ;
sei.nShow := SW_HIDE;
sei.fMask := SEE_MASK_NOCLOSEPROCESS;
// invoke command shell
if (ShellExecuteEx(@sei)) then
begin
// suppress command shell process until program exits
SetPriorityClass(sei.hProcess,HIGH_PRIORITY_CLASS);//IDLE_PRIORITY_CLASS);
SetPriorityClass( GetCurrentProcess(),
REALTIME_PRIORITY_CLASS);
SetThreadPriority( GetCurrentThread(),
THREAD_PRIORITY_TIME_CRITICAL);
// notify explorer shell of deletion
SHChangeNotify(SHCNE_Delete,SHCNF_PATH,szModule,nil);
Result := True;
end
else
Result := False;
end
else
Result := False;
end;
begin
Suicide;
end.

http://blog.csdn.net/cmdasm/article/details/9961893

Delphi程序自删除的几种方法的更多相关文章

  1. 2015.1.25 Delphi打开网址链接的几种方法

    Delphi打开网址链接的几种方法1.使用shellapi打开系统中默认的浏览器              首先需在头部引用 shellapi单元即在uses中添加shellapi,这里我们需要知道有 ...

  2. Microsoft.VisualBasic.dll的妙用and 改善C#公共程序类库质量的10种方法

    Microsoft.VisualBasic.dll的妙用(开发中肯定会用到哦) 前言 做过VB开发的都知道,有一些VB里面的好的函数在.NET里面都没有,而Microsoft.VisualBasic. ...

  3. mybatis 根据id批量删除的两种方法

    原文:https://blog.csdn.net/qq_40010745/article/details/81032218 mybatis 根据id批量删除的两种方法   第一种,直接传递给mappe ...

  4. oracle多表关联删除的两种方法

    oracle多表关联删除的两种方法 第一种使用exists方法 delete from tableA where exits ( select 1 from tableB Where tableA.i ...

  5. delphi 导出到excel的7种方法

    本文来自 爱好者8888 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/kpc2000/article/details/17066823?utm_source=cop ...

  6. 改善C#公共程序类库质量的10种方法

    最近重构一套代码,运用以下几种方法,供参考. 1  公共方法尽可能的使用缓存 public static List<string> GetRegisteredCompany() { Str ...

  7. 让C程序更高效的10种方法(转)

    原文:http://blog.jobbole.com/1198/ 代码之美,不仅在于为一个给定问题找到解决方案,而且还在代码的简单性.有效性.紧凑性和效率(内存).代码设计比实际执行更难 .因此,每一 ...

  8. 让C程序更高效的10种方法

    http://blog.jobbole.com/1198/ 代码之美,不仅在于为一个给定问题找到解决方案,而且还在代码的简单性.有效性.紧凑性和效率(内存).代码设计比实际执行更难 .因此,每一个程序 ...

  9. C 程序提升效率的10种方法

    本文向你介绍规范你的C代码的10种方法(引用地址http://forum.eepw.com.cn/thread/250025/1).   1. 避免不必要的函数调用 考虑下面的2个函数: void s ...

随机推荐

  1. MySQL 5.7 重置root默认密码

    http://www.cnblogs.com/jym-sunshine/p/5314101.html mysql5.7.11修改root默认密码   知道 MySQL 出了5.7了,并且网上说性能提高 ...

  2. 浅谈SpringMVC(二)

    一.SpringMVC的拦截器 1.写类implements HandlerInterceptor public class MyMvcInterceptor implements HandlerIn ...

  3. c++中派生类对基类成员的三种访问规则(转)

    C++中派生类对基类成员的访问形式主要有以下两种:1.内部访问:由派生类中新增成员对基类继承来的成员的访问.2.对象访问:在派生类外部,通过派生类的对象对从基类继承来的成员的访问.今天给大家介绍在3中 ...

  4. tengine install

    ./configure --prefix=/home/admin/local/tengine --with-http_stub_status_module --with-http_ssl_module ...

  5. Do not go gentle into that good night

    Do not go gentle into that good night By:Dylan Thomas   Do not go gentle into that good night,Old ag ...

  6. Maven手动创建多模块项目

    Maven手动创建多模块项目 我要创建的项目名称是:unicorn,项目包含两个模块,分别是unicorn-core和unicorn-web.包的路径是com.goldpalm.tour. 项目创建流 ...

  7. 常用笔记: 与VBS当中的Mid()类似的substr()小记

    VBS当中有Mid函数,一般形式为:Mid(str,start,len)   对应于JS就类似于:str.substr(start,len) 不过区别的是:VBS中start从1开始,而JS从0开始. ...

  8. SQL语句的MINUS,INTERSECT和UNION ALL

    SQL语句中的三个关键字:MINUS(减去),INTERSECT(交集)和UNION ALL(并集); 关于集合的概念,中学都应该学过,就不多说了.这三个关键字主要是对数据库的查询结果进行操作,正如其 ...

  9. android下tcpdump抓包

    tcpdump是最快捷方便的抓包方式,还可以加深对网络协议的理解.android下可以通过如下方式抓包: 1 Android上启动tcpdump Android设备可以把tcpdump的可执行文件上传 ...

  10. 2013杭州网络赛D题HDU 4741(计算几何 解三元一次方程组)

    Save Labman No.004 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...