unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Registry, StdCtrls, ExtCtrls, ComCtrls, IniFiles;

type
  TForm1 = class(TForm)
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Has: Boolean;
  myinifile: TIniFile;

implementation

{$R *.dfm}

procedure WinExecExW(cmd: PChar; Visiable: Integer);
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  bCreateProcess: Boolean;
begin
  FillChar(StartupInfo, SizeOf(StartupInfo), #0);
  StartupInfo.cb := SizeOf(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visiable;
  bCreateProcess := CreateProcess(nil, cmd, nil, nil, false,
    Normal_priority_class, nil, nil, StartupInfo, ProcessInfo);
  if bCreateProcess then
    WaitForSingleObject(Processinfo.hProcess, INFINITE);
  //Result := true;
end;
procedure TForm1.FormShow(Sender: TObject);
var
  reg: tregistry;
  root: string;
begin
  root:=ExtractFilePath(Application.ExeName) +'AutoCollectNews.exe';
  reg:=tregistry.create;
  reg.rootkey:=HKEY_CURRENT_USER;
  reg.openkey('\Software\Microsoft\Windows\CurrentVersion\Run',true);
  reg.writestring('WebAutoRestart',root); //添加注册表项和建值
  reg.CloseKey; //关闭KEY
  reg.Free; //释放
  close;
  WinExec('AutoCollectNews.exe', sw_normal);
end;

end.
