Link to home
Create AccountLog in
Avatar of pr2501
pr2501

asked on

How tu start my app after PC rebooting?

Will the timer in my app start automatically then?
ASKER CERTIFIED SOLUTION
Avatar of jimyX
jimyX

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of jimyX
jimyX

Or you can make a procedure to set your application either to auto start when Windows starts/reboots or not:

 
procedure TForm1.SetAutoRun(option: Boolean);
var
  MyReg: TRegistry;
begin
  MyReg:=TRegistry.Create;
  try
    MyReg.RootKey:=HKey_local_machine;
    MyReg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run', true);
    if option then
      begin
        if not MyReg.ValueExists('AppName') then
          begin
            MyReg.WriteString('AppName',Application.ExeName);
          end;
      end
    else
      begin
        if MyReg.ValueExists('AppName') then
          begin
            MyReg.DeleteValue('AppName');
          end;
      end;
    MyReg.CloseKey;
  finally
    MyReg.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetAutoRun(True);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  SetAutoRun(False);
end;

Open in new window


When Button1 is clicked your application will run when Windows starts:

Button2 will disable that.
or add a scheduled task at startup
Avatar of pr2501

ASKER

Thank you for  the  answer.
Can you help me  with:
[Pascal Error] Unit1.pas(27): E2003 Undeclared identifier: 'TRegistry'
Avatar of pr2501

ASKER

ok is here:
uses registry;