Solved

Startup with Windows

Posted on 2006-07-17
11
293 Views
Last Modified: 2010-04-05
Hi,

Anyone has a good method to start application automatically when the Windows started up ?

Function that can be used in a "preference" like this for example:

[ ] Start application automatically

[ Apply ] [ Cancel ]

That works with at least Windows 98/XP/2000.

Thanks.
0
Comment
Question by:kapot
  • 3
  • 2
  • 2
  • +4
11 Comments
 
LVL 24

Expert Comment

by:Tomas Helgi Johannsson
Comment Utility
   Hi!
The simplest way and works great in all Windows environments.
   In the Setup of your application put a shortcut in the Program Files\Startup folder.

Regards,
  Tomas Helgi
0
 
LVL 11

Expert Comment

by:calinutz
Comment Utility
Other way is to add to the registry in HKEY_Local_Machine/SOFTWARE/Microsoft/Windows/CurrentVersion/Run (or RunOnce) the path to your executable.

Regards
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
Hello,

Put your application in the Windows Registry, there are some keys that will make your application run with windows each time its started
Here's an example to put your application name

uses
  Registry;

procedure TForm1.Button1Click(Sender: TObject);
var
  Reg : TRegistry;
begin
  Reg := TRegistry.Create();
  Reg.RootKey := HKEY_CURRENT_USER;
  Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run',false);
  Reg.WriteString('AppName','AppPath');
  Reg.CloseKey;
  Reg.Free;
end;
if you need your application to run for one time, replace the key with this one

'\Software\Microsoft\Windows\CurrentVersion\RunOnce'

HTH

Regards,
Mohammed
0
 
LVL 11

Expert Comment

by:calinutz
Comment Utility
For this you can also use ready made delphi components that enables you to autorun on windows startup. Very easy to use.
Check out this component free for non comercial use:
http://www.abf-dev.com/abf-components.shtml

Or you can easily use the Registry to write your code into the registry so that your program start on Windows startup.
0
 
LVL 11

Expert Comment

by:calinutz
Comment Utility
:)
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 17

Expert Comment

by:TheRealLoki
Comment Utility
you could also turn your application into a service. If you have the startmode as automatic, it will start when windows starts, even if nobody logs on.
Depending on your verison of delphi, you can make a service by going alt-new-and choosing service application from teh list

f you want a real easy way to turn your application into a service, you can just use SVRANY.exe to run your app as a service.
This is available in the windows resource toolkit, and probably a million places online.
0
 
LVL 16

Expert Comment

by:CodedK
Comment Utility
Hi.

A smaller code similar to mnasman code :
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
procedure RunOnStartup(sProgTitle, sCmdLine    : string;  bRunOnce   : boolean );
var
  sKey : string;
  reg  : TRegIniFile;
begin
  if( bRunOnce )then
    sKey := 'Once'
  else
    sKey := '';

  reg := TRegIniFile.Create( '' );
  reg.RootKey := HKEY_LOCAL_MACHINE;
  reg.WriteString( 'Software\Microsoft'   + '\Windows\CurrentVersion\Run'  + sKey + #0, sProgTitle, sCmdLine );
  reg.Free;
end;
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
sProgTitle:
Name of your program.

sCmdLine:
This is the full path name to your executable program.

bRunOnce:
Set this to True if you want to run your program just once. If this parameter is False, specified program will be executed every time Windows starts up.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Hope this helps.
0
 
LVL 5

Accepted Solution

by:
Scay7 earned 155 total points
Comment Utility
just to add onto what the others said... :P great comments

I suggest a procedure like "doauto(query : boolean;user : string)"
where query is, is a true/false... true being set it false being remove it
where user is, is to which group... either current user or all users


put a 3 radiobuttonts somewhere on you form eg > settings > automatic startup or what ever

radiobutton1 = AutoRun - All Users
radiobutton2 = AutoRun - Current User
radiobutton3 = Disable

 ### code  ###
first put the procedure in :

type
  TForm1 = class(TForm)
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    procedure RadioButton1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure RadioButton3Click(Sender: TObject);
    procedure doauto(query : boolean;user : string);  // $#$ <---- like this over here $#$
  private
    { Private declarations }
  public
    { Public declarations }
  end;


Then you have :

procedure Tform1.doauto(query : boolean;user : string);
var
  Reg : TRegistry;
begin
if query = true then
begin
  Reg := TRegistry.Create;
  try
      if user = 'single' then Reg.RootKey := HKEY_CURRENT_USER;
      if user = 'all' then Reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', True) then
    begin
    Reg.WriteString('AppName','AppPath');
    //appname - what ever you want the key to be called
    //apppath - FULL dir of where you app is installed eg c:\program files\test\test.exe
    Reg.CloseKey;
    end;
  finally
    Reg.Free;
    inherited;
  end;
end;
if query = false then
begin
  Reg := TRegistry.Create;
  try
    if user = 'alsi' then Reg.RootKey := HKEY_CURRENT_USER;
    Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', false);
      if Reg.DeleteValue('AppName') then showmessage('The Automatic Start-Up, has been Disabled for the current user...');
    //appname - the name of the key you specified above
    if user = 'alsi' then Reg.RootKey := HKEY_LOCAL_MACHINE;
    Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', false);
      if Reg.DeleteValue('AppName') then showmessage('The Automatic Start-Up, has been Disabled for all users...');
    //appname - the name of the key you specified above
  finally
    reg.CloseKey;
    Reg.Free;
    inherited;
  end;
end;

end;

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
doauto(true,'all'); // set auto for all users :p
end;

procedure TForm1.RadioButton2Click(Sender: TObject);
begin
doauto(true,'single'); // set auto for current user :P
end;

procedure TForm1.RadioButton3Click(Sender: TObject);
begin
doauto(false,'alsi'); // disable auto for both groups
end;

### CODE ###


Peace Scay7

0
 

Author Comment

by:kapot
Comment Utility
Scay7, your code looks promising. I will try it tonight and let you know the outcome.
0
 
LVL 5

Expert Comment

by:Scay7
Comment Utility
and ?
0
 

Author Comment

by:kapot
Comment Utility
It works :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

19 Experts available now in Live!

Get 1:1 Help Now