Solved

Starting on Windows Logon

Posted on 2003-11-12
1
215 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Title # Comments Views Activity
Delphi Mdi application Child forms get behind control 7 308
Print Graphic and Text to Epson TM-T88v 12 465
creating threads in delphi 1 163
Base1 Encode/Decode 3 86
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…

749 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