Delphi程序自删除的几种方法
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程序自删除的几种方法的更多相关文章
- 2015.1.25 Delphi打开网址链接的几种方法
Delphi打开网址链接的几种方法1.使用shellapi打开系统中默认的浏览器 首先需在头部引用 shellapi单元即在uses中添加shellapi,这里我们需要知道有 ...
- Microsoft.VisualBasic.dll的妙用and 改善C#公共程序类库质量的10种方法
Microsoft.VisualBasic.dll的妙用(开发中肯定会用到哦) 前言 做过VB开发的都知道,有一些VB里面的好的函数在.NET里面都没有,而Microsoft.VisualBasic. ...
- mybatis 根据id批量删除的两种方法
原文:https://blog.csdn.net/qq_40010745/article/details/81032218 mybatis 根据id批量删除的两种方法 第一种,直接传递给mappe ...
- oracle多表关联删除的两种方法
oracle多表关联删除的两种方法 第一种使用exists方法 delete from tableA where exits ( select 1 from tableB Where tableA.i ...
- delphi 导出到excel的7种方法
本文来自 爱好者8888 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/kpc2000/article/details/17066823?utm_source=cop ...
- 改善C#公共程序类库质量的10种方法
最近重构一套代码,运用以下几种方法,供参考. 1 公共方法尽可能的使用缓存 public static List<string> GetRegisteredCompany() { Str ...
- 让C程序更高效的10种方法(转)
原文:http://blog.jobbole.com/1198/ 代码之美,不仅在于为一个给定问题找到解决方案,而且还在代码的简单性.有效性.紧凑性和效率(内存).代码设计比实际执行更难 .因此,每一 ...
- 让C程序更高效的10种方法
http://blog.jobbole.com/1198/ 代码之美,不仅在于为一个给定问题找到解决方案,而且还在代码的简单性.有效性.紧凑性和效率(内存).代码设计比实际执行更难 .因此,每一个程序 ...
- C 程序提升效率的10种方法
本文向你介绍规范你的C代码的10种方法(引用地址http://forum.eepw.com.cn/thread/250025/1). 1. 避免不必要的函数调用 考虑下面的2个函数: void s ...
随机推荐
- Spring中注入List,Set,Map,Properties的xml文件配置方法
下面的例子展示了如何注入 List – <list/> Set – <set/> Map – <map/> Properties – <props/> ...
- 一键搞定Java桌面应用安装部署 —— exe4j + Inno Setup 带着JRE, 8M起飞
转载自:http://www.blogjava.net/huliqing/archive/2008/04/18/193907.html 对于作Java桌面应用来说,比较烦人的就是安装部署问题,客户端是 ...
- 关于SVM一篇比较全介绍的博文
转自:http://blog.csdn.net/v_july_v/article/details/7624837 支持向量机通俗导论(理解SVM的三层境界) 前言 动笔写这个支持向量机(support ...
- java 笔试
单例设计模式: public class Singliton { //no new private Singliton (){ } static Singliton ins = null; publi ...
- java 乱码详解_jsp中pageEncoding、charset=UTF -8"、request.setCharacterEncoding("UTF-8")
http://blog.csdn.net/qinysong/article/details/1179480 java 乱码详解__jsp中pageEncoding.charset=UTF -8&quo ...
- openwrt看IP流量
可以利用iptable来实现的,看附件的脚本. 把他放到路由器里面,然后运行. #!/bin/sh echo "Collecting data..." echo "&qu ...
- JS图标插件
1.web开发中,有时候需要图标等控件,amcharts可以胜任. amcharts官方网址:http://www.amcharts.com/javascript-charts/
- Pro/E 5.0安装图解教程(也适用于Creo Elements/Pro 5.0)
安装前必读:☆ 本教程适用于 32 位 proe 5.0 M010,M020,M030,M040,M050,M060 过程完全一样:☆ 本教程用于 64 位 proe 5.0 M010,M020,M0 ...
- 害人的VS2008,manifest导致“应用程序配置不正确,应用程序未能启动”
在VC++2008的项目中,如何显示地指定要使用的C++库的版本? 开发环境:VS2008 SP1 + Win2003 SP2 因为我的VS2008安装了SP1补丁,所以有了9.0.3 ...
- Codeforces Round#2
A. Winner 题目大意:一些人在玩游戏,给出n次某人获得的分数,现在请计算出胜者,如果不止一个最高分,则取最先达到该分数的人. 题解:模拟得分过程,首先计算出最高分,然后获取先到达或超过最高分的 ...