1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Launching an application at Windows Startup

Discussion in 'Delphi Programming' started by AdminDF, Dec 5, 2013.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    The typical way for letting an application start on Windows' startup, is to create a shortcut to its exe-file in the Startup folder of the Start menu. But you also can control this behaviour by making changes to the registry from within a Delphi program.


    You can write a value to one of two keys in the Windows Registry under the HKEY_LOCAL_MACHINE root key:


    Software\Microsoft\Windows\CurrentVersion\RunOnce: the application will start just ONCE, on the next startup of Windows. Afterwards, the new registry key is deleted automatically.
    Software\Microsoft\Windows\CurrentVersion\Run: in this case, the application will start on EVERY Windows startup. The registry key that was created will stay in the registry, until you delete it.
    Here's the Delphi source code for such a procedure:


    Code:
    procedure RunOnWinStart(ApTitle, ApPathFile: string;
      RunOnce: Boolean);
    var
      Reg: TRegistry;
      TheKey: string;
    begin
      Reg := TRegistry.Create;
      Reg.RootKey := HKEY_LOCAL_MACHINE;
      TheKey := 'Software\Microsoft\Windows\CurrentVersion\Run';
      if RunOnce then TheKey := TheKey + 'Once';
      // Open key, or create it if it doesn't exist
      Reg.OpenKey(TheKey, True);
      Reg.WriteString(ApTitle, ApPathFile);
      Reg.CloseKey;
      Reg.Free;
    end;


    The meaning of the parameters:
    ApTitle: title of the application. This can be any value you want, but it's best to use something meaningful that you can recognize later on.
    ApPathFile: the full path and file name of the executable file that you want to launch.
    RunOnce: to run an application just once, pass True. If the application must be started each time that Windows starts, pass False.
    Examples:


    Code:
     RunOnWinStart('TestProgram', 'c:\test\testprog.exe', True);
      RunOnWinStart('Calculator', 'calc.exe', False);


    Note: in the second example, we don't have to give the full path of calc.exe, because Windows knows where to find this program.


    When Windows starts up, it launches all the applications listed in the RunOnce key and all those in the Run key. Afterwards, the entries of the RunOnce key are deleted by Windows, but these in the Run key are left untouched.
     

Share This Page