How to Add or Remove Startup Items in Delphi

Two methods for Delphi which allow you to add or remove Startup Items in Delphi providing means for your application to run on startup.

By Tim Trott | Legacy Code | February 6, 2004

These methods will allow you to easily add or remove startup entries to the system registry to auto-load applications when Windows loads.

pascal
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('\Software\Microsoft\Windows\CurrentVersion\Run' + 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('\Software\Microsoft\Windows\CurrentVersion\Run', sProgTitle);
  reg.Free;
end;
Code snippet, programming
How to Add or Remove Startup Items in Delphi
Was this article helpful to you?
 

Related ArticlesThese articles may also be of interest to you

CommentsShare your thoughts in the comments below

If you enjoyed reading this article, or it helped you in some way, all I ask in return is you leave a comment below or share this page with your friends. Thank you.

There are no comments yet. Why not get the discussion started?

We respect your privacy, and will not make your email public. Learn how your comment data is processed.