whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

60 Visitors Online


 
...run a Program automatically at Windows start-up?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (36):  
     


uses
  
Registry;

procedure SetAutoStart(AppName, AppTitle: string; bRegister: Boolean);
const
  
RegKey = '\Software\Microsoft\Windows\CurrentVersion\Run';
  // or: RegKey = '\Software\Microsoft\Windows\CurrentVersion\RunOnce';
var
  
Registry: TRegistry;
begin
  
Registry := TRegistry.Create;
  try
    
Registry.RootKey := HKEY_LOCAL_MACHINE;
    if Registry.OpenKey(RegKey, False) then
    begin
      if 
bRegister = False then
        
Registry.DeleteValue(AppTitle)
      else
        
Registry.WriteString(AppTitle, AppName);
    end;
  finally
    
Registry.Free;
  end;
end;

// Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
  
// 1.Parameter: Path to your Exe-File
  // 2. Parameter: the Title of your Application
  // 3. Set (true) or Unset (false) Autorun
  
SetAutoStart(ParamStr(0), 'Title of your Application', True);
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners