README.md

December 5, 2022 ยท View on GitHub

Run Program On Startup (Registry)

Description

Places your program in the Windows Registry so it will run at startup.

More Info

Submitted On
ByCrAcKeR
LevelIntermediate
User Rating4.5 (18 globes from 4 users)
CompatibilityDelphi 5, Delphi 4, Pre Delphi 4
CategoryRegistry
WorldDelphi
Archive File

Source Code

// Place registry in your USES
uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, registry, StdCtrls;
// This is the procedure (False means remove, True means create)
procedure RunOnStartup(sProgTitle, sCmdLine: string; bStartup: boolean );
var
 sKey: string;
 reg : TRegIniFile;
begin
 sKey := ''; //sKey := 'Once' if you wish it to only run on the next time you startup.
 if bStartup = false then //If value passed is false, then value deleted from Registry.
 begin
 try
 reg := TRegIniFile.Create( '' );
 reg.RootKey := HKEY_LOCAL_MACHINE;
 reg.DeleteKey(
  'Software\Microsoft'
  + '\Windows\CurrentVersion\Run'
  + sKey + #0,
  sProgTitle);
 reg.Free;
 exit;
 except //Using Try Except so that if value can not be placed in registry, it
 //will not give and error.
 end;
end;
try
 reg := TRegIniFile.Create( '' );
 reg.RootKey := HKEY_LOCAL_MACHINE;
 reg.WriteString(
  'Software\Microsoft'
  + '\Windows\CurrentVersion\Run'
  + sKey + #0,
  sProgTitle,
  sCmdLine );
 reg.Free;
 except
 end;
 end;