function SetAutoRun(FName, sKey_Name : String) : Boolean;
const
  sKey_Run          = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run';
var
  RegKey: HKEY;
begin
  Result := False;
  if RegOpenKey(HKEY_LOCAL_MACHINE, sKEY_Run, RegKey) = ERROR_SUCCESS then
    try
      if FName = '' then
        Result := RegDeleteValue(RegKey, sKey_Name) = ERROR_SUCCESS
      else
        Result := RegSetValueEx(RegKey, sKey_Name, 0, REG_SZ, PChar(FName), Length(FName)) = ERROR_SUCCESS;
    finally
      RegCloseKey(RegKey);
    end;
end;调用为SetAutoRun(Application.FileName, '我的程序');

解决方案 »

  1.   

    在这个下写进你程序的文件名即运行路径就行了
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
      

  2.   

    在窗体创建时写如下代码:
    procedure TForm1.FormCreate(Sender: TObject);
    var
      R:TRegistry;
    begin
      R:=TRegistry.Create;
      R.RootKey:=HKEY_LOCAL_MACHINE;
      R.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run',True);
      R.WriteString('MyApp',Application.ExeName);
      R.CloseKey;
      R.Free;
    end;
    如果想程序在后台运行可以在窗体创建过程中写上
    Application.ShowMainForm:=False;就可以了