Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Starting on Windows Logon

Posted on 2003-11-12
1
214 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
ID: 9736234
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 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