Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

load my app at windows startup 2

Status
Not open for further replies.

Gigatech

Programmer
Jul 12, 2000
80
0
0
CR
Hi, I use Delphi 7.

What is the best way (by code inside my program) to let the user choose to run the program at windows startup?

Thanks

 
You can get your program to write its application name to the run key in the registry.

HKEY_LOCAL_MACHINE/software/microsoft/windows/currentversion/run

e.g.
Code:
// write the application to the Windows run key
procedure AddToStartup(Name, AppPath: string);
var path: string;
begin
   FInifile := TRegIniFile.Create('Software');
   with FIniFile do
     begin
      path := 'Software\Microsoft\Windows\CurrentVersion\Run';
        RootKey := HKEY_LOCAL_MACHINE;
        if ReadString(Path, Name, '') <> AppPath then
            WriteString(Path, Name, AppPath);
        Free;
     end;
end;

The user will have to have administror previlages under XP and NT/2000

Steve
Time for a new sig a bit of DNA I think will scan books and get back to you.
 
I got a slightly different version from somewhere.... maybe a combination of the two???

Code:
//=================================================
//Run/Runonce program at system startup
//=================================================
Procedure OnStartup (const PgmTitle, CmdLine: String; RunOnce: boolean);
Var
  Key : String;
  Reg : TRegIniFile;
Begin 
  If RunOnce Then 
    Key := 'Once' #0
  Else 
    Key := #0; 
  Reg := TRegIniFile.create (''); 
  Reg.RootKey := HKEY_LOCAL_MACHINE; 
  Reg.WriteString ('Software\Microsoft\Windows\CurrentVersion\Run' + Key, 
    PgmTitle, CmdLine); 
  Reg.Free
End;



Regards and HTH,
JGS
 
[sijgs]
I hope its different [smile], I wrote the code I posted myself, its part of my own product registration engine. Based on the Delphi help examples.



Steve
Time for a new sig a bit of DNA I think will scan books and get back to you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top