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 ...
随机推荐
- Linux下文件及目录的一些操作(附递归遍历目录源码)
1.获取当前工作目录 #include <unistd.h> 1.char *getcwd(char *buf,size_t size); 2. 3.其中,buf为缓冲区地址,size为给 ...
- 初识eclipse及配置相关
1. Eclipse 导入外部项目无法识别为Web项目并无法再部署到tomcat解决办法: http://www.cnblogs.com/heshan664754022/archive/2013/05 ...
- hive 行转列 并添加虚列
select regexp_extract(a.col2,'(phonenum=\")(.*?)\"',2) user_device, regexp_extract(a.col13 ...
- MongoDB入门学习(一)—— 安装和启动
最近由于工作需要,开始学习MongoDB数据库了.第一篇博文就从这里开始吧,以此记录下学习中的点点滴滴,为自己加油呢! (一) MongoDB简介 网上搜搜了一下:(来源:http://www.run ...
- SDOI2008 Sandy的卡片( 后缀数组 )
求出后缀数组, 然后二分答案, 对height数组分组检验答案. 时间复杂度O(|S| log|S|) ------------------------------------------------ ...
- The following classes could not be found: - android.support.v7.internal.widget.ActionBarOverlayLayou解决方案
如图出现如下的错误的时候,一般都是升级Androdi Studio 后导致的,引入库不全,或者其他 东西缺少,可以如下解决方案: 或者如下的解决方案: 在布局文件的Design界面中,修改原来的App ...
- Spring集成Quartz定时器
<!-- Spring集成Quartz开始 --> <bean id="startQuertz" lazy-init="false" auto ...
- clear:both后margin-top不起作用
如: <div style="float:left;">float:left</div> <div style="clear:both;ma ...
- UIWindow 详解
UIWindow对象是所有UIView的根视图,管理和协调的应用程序的显示.分发事件给View.UIWindow类是UIView的子类,可以看作是特殊的UIView.一般应用程序只有一个UIWindo ...
- cocos2dx tag和zorder
当一个渲染对象加入到两外一个渲染对象中时,可以有两个可选参数,一个时tag,一个是order virtual void addChild(CCNode * child); virtual void a ...