unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure GetRunState();
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
const
  paths = 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths';

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  GetRunState();
end;

procedure TForm1.GetRunState();
var
  reg: TRegistry;
begin
  //Определем, зарегистрировано ли приложение для запуска из
  //командной строки
  reg := TRegistry.Create();
  reg.RootKey := HKEY_LOCAL_MACHINE;
  if reg.OpenKey(paths, False) then
  begin
    CheckBox1.Checked := reg.KeyExists(Application.Title + '.exe');
    reg.CloseKey();
  end;
  reg.Free();
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  reg: TRegistry;
begin
  reg := TRegistry.Create();
  reg.RootKey := HKEY_LOCAL_MACHINE;
  if CheckBox1.Checked then
  begin
    //Регистрируем программу для запуска по имени из командной строки
    if reg.OpenKey(paths + '\' + Application.Title + '.exe', True) then
    begin
      reg.WriteString('', Application.ExeName);
      reg.CloseKey();
    end;
  end
  else
  begin
    //Удаляем информацию из реестра
    if reg.OpenKey(paths, False) then
    begin
      reg.DeleteKey(Application.Title + '.exe');
      reg.CloseKey();
    end;
  end;
  reg.Free();
  GetRunState();
end;

end.
