DelphiFAQ Home Search:

Run your application on Startup programatically

 

comments2 comments. Current rating: 3 stars (2 votes). Leave comments and/ or rate it.

Sometimes you may need to have an application run once (or every time) on Windows
startup time. The following code contains the function OnStartup which shows to do this
with the means of the operating system.
Use OnStartup e.g. like this:

OnStartup('any title does not matter', 'c:\temp\runthis.exe', true);
to run your application "runthis.exe" exactly one time.

Procedure OnStartup (const PgmTitle, CmdLine: String; RunOnce: boolean);
Var
  Key : String;
  Reg : TRegIniFile;
Begin 
  If RunOnce Then 
    Key := 'Once' #0
  Else 
    Key := #0; 
  Reg := TRegIniFile.create (''); 
  Reg.RootKey := HKEY_LOCAL_MACHINE; 
  Reg.WriteString ('Software\Microsoft\Windows\CurrentVersion\Run' + Key, 
    ProgTitle, CmdLine); 
  Reg.Free
End;

Comments:

2008-02-27, 06:57:41
anonymous  
rating
What the hell does that mean? English, PLEEEESE!!!!
2008-04-16, 16:41:35   (updated: 2008-04-16, 16:42:03)
vampwitch  
rating
You forgot to add 'Registry' in the uses clause ;)

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: