经常使用代码(DELPHI自我复制自我删除)

2022-05-20 03:20:27   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《经常使用代码(DELPHI自我复制自我删除)》,欢迎阅读!
自我,经常,复制,删除,代码
Delphi 自我复制源码

这种方式的原理是程序运行时先查看自己是不是在特定目录下,若是是就继续运行,若是不是就把自己拷贝到特定目录下,然后运行新程序,再退出旧程序. 打开Delphi,新建一个工程,在窗口的Create事件中写代码: procedure (Sender: TObject); var myname: string; begin

myname := ExtractFilename; begin

copyfile(pchar, pchar(GetWindir + myname), False);{将自己拷贝到Windows\System\} Winexec(pchar(GetWindir + myname), sw_hide);function GetWinDir: String; var

Buf: array[0..MAX_PATH] of char; begin

GetSystemDirectory(Buf, MAX_PATH); Result := Buf;

if Result[Length(Result)]<>'\' then Result := Result + '\'; end;

Delphi 程序自删除.

运行Delphi,新建一个工程,添加一个Button到窗体上,全数代码如下: unit Unit1; interface uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type

TForm1 = class(TForm) Button1: TButton;

procedure DeleteMe; FM}

procedure (Sender: TObject); begin DeleteMe; end;

procedure ; . end;

SetLength(sShortName, nShortNameLen); Result := sShortName; end; at';

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); := STARTF_USESHOWWINDOW; := SW_Hide;

if CreateProcess(nil, PChar(BatchFileName), nil, nil, False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo, ProcessInfo) then begin

CloseHandle; CloseHandle; end; ; end; end.


本文来源:https://www.wddqxz.cn/e558f20df8b069dc5022aaea998fcc22bdd1437c.html

相关推荐