Learning never exhausts the mind
Home >  Coding > Legacy Code > Add Or Remove Startup Items in Delphi

Last Updated on by

These two short methods will allow you to easily add or remove program startup entries to the system registry to auto load applications when Windows loads.
procedure RunOnStartup(sProgTitle, sCmdLine: string; bRunOnce: boolean );
var
  sKey : string;
  reg  : TRegIniFile;
begin
  if( bRunOnce )then
    sKey := 'Once'
  else
    sKey := '';

  reg := TRegIniFile.Create( '' );
  reg.RootKey := HKEY_LOCAL_MACHINE;
  reg.WriteString('SoftwareMicrosoftWindowsCurrentVersionRun' + sKey + #0, sProgTitle, sCmdLine );
  reg.Free;
end;

procedure RemoveOnStartup(sProgTitle: string);
var
  sKey : string;
  reg  : TRegIniFile;
begin
  reg := TRegIniFile.Create( '' );
  reg.RootKey := HKEY_LOCAL_MACHINE;
  reg.DeleteKey('SoftwareMicrosoftWindowsCurrentVersionRun', sProgTitle);
  reg.Free;
end;

Leave a Reply

Fields marked with * are mandatory.

We respect your privacy, and will not make your email public. Hashed email address may be checked against Gravatar service to retrieve avatars. This site uses Akismet to reduce spam. Learn how your comment data is processed.