(page requirements)

How to programmatically make your programs run on Windows startup

It's easy enough to drag and drop your application to the Windows Startup group to make it run on Windows startup. But, if you wanted to do this from your program, at the end of your setup program for example, or if you wanted to make your program run just once the next time Windows start, following function might come in handy:
 
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).
 
 
Applicable Keywords : Delphi, Delphi 2.x, Delphi 3.x, Functions, Windows NT, Windows NT 3.x, Windows NT 4.x, Windows, Win32, Windows 95
 
 
 
Copyright © 2009 Chami.com. All Rights Reserved. | Advertise | Created in HTML Kit editor