Solved

Starting on Windows Logon

Posted on 2003-11-12
1
210 Views
Last Modified: 2010-04-05
Hey,

I have a checkbox how would I make it that if I click on the checkbox and it checks that the program will start up on windows logon.

And also how do I make the program remember that the checkbox has been checked and keep it checked so you dont have to keep on checking it for each time you want to start the program on windows logon,

Cheers,

Computer Programer
0
Comment
Question by:computerprogramer
1 Comment
 
LVL 6

Accepted Solution

by:
DaFox earned 20 total points
Comment Utility
Hi,

> I have a checkbox how would I make it that if I click on the checkbox and it checks that the program
> will start up on windows logon.

uses Registry;

procedure TForm1.Button1Click(Sender: TObject);
// register application
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CURRENT_USER;
  Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run', True);
  Reg.WriteString('nameOfApplication', ParamStr(0));
  Reg.Destroy;
end;

procedure TForm1.Button2Click(Sender: TObject);
// delete application from autostart
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CURRENT_USER;
  Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run', True);
  Reg.DeleteValue('nameOfApplication');
  Reg.Destroy;
end;

>> And also how do I make the program remember that the checkbox has been checked and keep
>> it checked so you dont have to keep on checking it for each time you want to start the program
>> on windows logon,

Use IniFiles or the registry! Sth. like:

// ...
var
  ini: TIniFile;
begin
  ini := TIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));
  try
    ini.WriteBool('Options', 'doAutostart', CheckBox.Checked);
  finally
    FreeAndNil(ini); //Datei Schliessen/Freigeben
  end;
// ...

// ...
  CheckBox.Checked := ini.ReadBool('Options', 'doAutostart', false);
// ...

If you want to use the registry it's more or less the same as above.

Markus
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now