Home
Portfolio
3D Art/Animation
Programming
Tutorials
3D Art/Animation
Programming
Work In Progress
The Interview
Ex-Smokers logos
Programming
About Me
|
It is often desirable to have a program start itself
automatically when Windows starts. This can be accomplished with
some very simple steps:
- On your programs Settings or Preferences form, place a TCheckBox
with the caption Run at Windows Startup.
- In the forms uses clause, include the unit Registry.
- In the TCheckBox On Click event, include the following code:
procedure TForm1.TCheckBox1Click(Sender: TObject);
var Registry: TRegistry;
begin
Registry := TRegistry.Create;
Registry.RootKey := HKEY_LOCAL_MACHINE;
Registry.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run', false);
If TCheckBox1.Checked then
Registry.WriteString(Application.Title, Application.ExeName)
else
Registry.DeleteValue(Application.Title);
Registry.CloseKey;
Registry.free;
end;
- To ensure that the TCheckBox displays the current status of
the function when the form is displayed, we need to insert the
following code into the forms On Show event:
procedure TForm1.FormShow(Sender: TObject);
var Registry : TRegistry;
begin
Registry := TRegistry.Create;
Registry.RootKey := HKEY_LOCAL_MACHINE;
Registry.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run', false);
CheckBox1.Checked := Registry.ValueExists(Application.Title);
Registry.CloseKey;
Registry.free;
end;
This code simply checks to see if the run command for the appllication
has been inserted into the registry. If it has, the the TCheckBox
is checked, otherwise it is not.
That is all there is to it.
|
Previous tutorial |
Next tutorial |
|