


全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
此文档收集于网络,如有侵权,请联系网站删除Delphi 自我复制源码这种方法的原理是程序运行时先查看自己是不是在特定目录下,如果是就继续运行,如果不是就把自己拷贝到特定目录下,然后运行新程序,再退出旧程序.打开Delphi,新建一个工程,在窗口的Create事件中写代码:procedure TForm1.FormCreate(Sender: TObject);var myname: string;beginmyname := ExtractFilename(Application.Exename); /获得文件名if application.Exename GetWindir + myname then /如果文件不是在WindowsSystem那么.begincopyfile(pchar(application.Exename), pchar(GetWindir + myname), False);将自己拷贝到WindowsSystem下Winexec(pchar(GetWindir + myname), sw_hide);/运行WindowsSystem下的新文件application.Terminate;/退出end;end;其中GetWinDir是自定义函数,起功能是找出WindowsSystem的路径.function GetWinDir: String;varBuf: array0.MAX_PATH of char;beginGetSystemDirectory(Buf, MAX_PATH);Result := Buf;if ResultLength(Result) then Result := Result + ;end;Delphi 程序自删除.运行Delphi,新建一个工程,添加一个Button到窗体上,全部代码如下:unit Unit1;interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;typeTForm1 = class(TForm)Button1: TButton;procedure DeleteMe; /自定义程序自杀过程procedure Button1Click(Sender: TObject);private Private declarations public Public declarations end;varForm1: TForm1;implementation$R *.DFMprocedure TForm1.Button1Click(Sender: TObject);beginDeleteMe;end;procedure TForm1.DeleteMe; /程序自杀/-function GetShortName(sLongName: string): string; /转换长文件名varsShortName: string;nShortNameLen: integer;beginSetLength(sShortName, MAX_PATH);nShortNameLen := GetShortPathName(PChar(sLongName),PChar(sShortName), MAX_PATH - 1);if (0 = nShortNameLen) thenbegin/ handle errors.end;SetLength(sShortName, nShortNameLen);Result := sShortName;end;/-varBatchFile: TextFile;BatchFileName: string;ProcessInfo: TProcessInformation;StartUpInfo: TStartupInfo;beginBatchFileName := ExtractFilePath(ParamStr(0) + $Delme$.bat;AssignFile(BatchFile, BatchFileName);Rewrite(BatchFile);Writeln(BatchFile, :try);Writeln(BatchFile, del + GetShortName(ParamStr(0) + );Writeln(BatchFile, if exist + GetShortName(ParamStr(0) + + goto try);Writeln(BatchFile, del %0);Writeln(BatchFile, cls);Writeln(BatchFile, exit);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) th
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 顺普培训考试题库及答案
- 2025年新疆农作物制种合作合同协议
- 2025年物业管理人员考核合同
- 机电维修班考试题及答案
- 招募管理师考试题及答案
- 工会职工技能考试题库及答案
- 青协组织笔试题目及答案
- 中国近代史事件历史基础知识试题及答案
- 城乡发展差异地理基础知识试题及答案
- pvc采购合同(标准版)
- 茶百道授权协议书
- 科技公司员工管理规章制度范文
- 院感相关知识课件
- 2025-2030中国网络直播行业市场深度调研及前景趋势与投资研究报告
- 糖尿病基础知识课件
- 《中国脑卒中防治报告(2023)》
- 项目经理转正述职报告
- 葡萄胎完整课件
- 2025年事务所年度工作总结(3篇)
- 代办离职委托书模板文档
- 急性颈髓损伤病情观察护理
评论
0/150
提交评论