procedure TfrmMain.SetAutoRun(isRun: Boolean);
var
oAutoRunRegister: TRegistry;
begin
oAutoRunRegister := TRegistry.Create;
try
oAutoRunRegister.RootKey := HKEY_CURRENT_USER;
oAutoRunRegister.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', False);
if isRun then
begin
if not oAutoRunRegister.ValueExists('appEXEName') then
begin
oAutoRunRegister.WriteString('appEXEName' , Application.ExeName);
end;
end
else
begin
if oAutoRunRegister.ValueExists('appEXEName') then
begin
oAutoRunRegister.DeleteValue('appEXEName');
end;
end;
finally
oAutoRunRegister.Free;
end;
end;