Web Design that taps into the haromny and vision of your dreams.

Add Or Remove Startup Items in Delphi

By on in Coding

67 words, estimated reading time 1 minutes.

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;

Last updated on: Saturday 24th June 2017

 

Comments

Have a question or suggestion? Please leave a comment to start the discussion.

 

Leave a Reply

Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Your email address will not be published.