Beranda > Delphi > How to programmatically make your programs run on Windows startup

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(
    'Software\Microsoft\Windows\CurrentVersion\Run' + sKey + #0,
    sProgTitle,
    sCmdLine
  );
  reg.Free;
end;

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);
Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. Oktober 12, 2015 pukul 12:53 am

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: