Automatically Start

How to register myapplication.exe into registry, make
it automatically start when each time windows start up.
(don't use put it into startup group solution)

Thanks & Rgds

Shekou
shekouAsked:
Who is Participating?
 
thomasphlipsConnect With a Mentor Commented:
*** autostartup ***

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 StdCtrls, registry;

type
 TForm1 = class(TForm)
   Button1: TButton;
   procedure Button1Click(Sender: TObject);
   procedure RunOnStartup(sProgTitle, sCmdLine: string; bStartup: boolean );
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
 Form1.RunOnStartup('', ParamStr(0), False);
end;

procedure TForm1.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;


0
 
thomasphlipsCommented:
and ... does it work????
0
 
CalvinDayCommented:
Same thing - Short form:
  fRun:='C:\windows\MyProgram.EXE';
  with TRegIniFile.Create('') do
    begin
    RootKey:=HKEY_LOCAL_MACHINE;
    WriteString('Software\Microsoft\Windows\CurrentVersion\Run'+#0,'MyProgram',fRun);
    Free;
    end;

0
All Courses

From novice to tech pro — start learning today.