Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Startup with Windows

Posted on 2006-07-17
11
Medium Priority
?
308 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
[X]
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
  • 3
  • 2
  • 2
  • +4
11 Comments
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 17120698
   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
ID: 17120892
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:Mohammed Nasman
ID: 17120899
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:calinutz
ID: 17120915
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
ID: 17120918
:)
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17124810
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
ID: 17125853
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 620 total points
ID: 17126173
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
ID: 17128496
Scay7, your code looks promising. I will try it tonight and let you know the outcome.
0
 
LVL 5

Expert Comment

by:Scay7
ID: 17160915
and ?
0
 

Author Comment

by:kapot
ID: 17369848
It works :)
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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

660 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