Friday, January 14, 2011

How to programmatically make your programs run on Windows startup

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(
    'SoftwareMicrosoft'
    + 'WindowsCurrentVersionRun'
    + sKey + #0,
    sProgTitle,
    sCmdLine );
  reg.Free;
end;
Listing #1 : Delphi code. Download wstartup (0.38 KB).
 
Usage:
 
sProgTitle:
Name of your program. Generally speaking, this could be anything you want.
sCmdLine:
This is the full path name to your executable program.
bRunOnce:
Set this to True if you want to run your program just once. If this parameter is False, specified program will be executed every time Windows startsup.
 
Example:
 
RunOnStartup(
  'Title of my program',
  'MyProg.exe',
  False );
Listing #2 : Delphi code. Download demo (0.18 KB)
 

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Kang Iwan K-sev | Thank's for your visit To My Site - Ridwan Mulyana | Cibeureum