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 ...
随机推荐
- Android自定义View和控件之一-定制属于自己的UI
照例,拿来主义.我的学习是基于下面的三篇blog.前两是基本的流程,第三篇里有比较细致的绘制相关的属性.第4篇介绍了如何减少布局层次来提高效率. 1. 教你搞定Android自定义View 2. 教你 ...
- xmanager 使用
linux 上安装xterm windows上启动命令: /usr/bin/xterm -ls -display $DISPLAY
- 在View中使用CGridCtrl时出现系统异常
一.简介 我的程序是单文档程序,我的View视图需要使用CGridCtrl,于是我把CGridCtrl作为子窗口嵌入到View中覆盖住整个View.由于不能像gridctrl_demo227那样直接在 ...
- Control的Invoke和BeginInvoke详解
(一)Control的Invoke和BeginInvoke 我们要基于以下认识: (1)Control的Invoke和BeginInvoke与Delegate的Invoke和BeginInvoke是不 ...
- Android 修改host文件的3种方法
Android修改hosts文件的方法介绍 本文介绍三种Android手机修改hosts文 件的方法,但修改hosts文件一定要谨慎:Android手机hosts文件的换行符必须是n而不是window ...
- Android学习笔记(不定时更新)
<2014-03-20>设置按钮的不同状态 1.res/ layout/ [文件名]myselector.xml 2.把两张不同的按钮图片放到drawable-xxxx文件夹里,mysel ...
- [LeetCode]题解(python):145-Binary Tree Postorder Traversal
题目来源: https://leetcode.com/problems/binary-tree-postorder-traversal/ 题意分析: 后序遍历一棵树,递归的方法很简单,尝试用非递归的方 ...
- 树型动态规划(树形dp)
树型动态规划就是在“树”的数据结构上的动态规划,树型动态规划是建立在树上的,所以有二个方向: 1.根—>叶:这种题目基本上碰不到 2.叶->根:根的子节点传递有用的信息给根,完后根得出最优 ...
- iPhone 5s网络钓鱼邮件,和苹果发布会同步亮相
正如预期的一样,网络犯罪分子会利用Apple最新发表的iPhone 5s消息,几乎在苹果的新产品发表会同时,这个网络钓鱼(Phishing)信件开始流传.此次,趋势科技病毒防治中心 Trend Lab ...
- react-native 入门资源合集
# 了解react-native React Native enables you to build world-class application experiences on native pla ...