Run Program on Windows startup

Please discuss general Delphi programming topics here.

Run Program on Windows startup

Postby Blod » August 4th, 2008, 2:59 pm

Hello,

I've been using the code below to have a program automatically start up with Windows.
It works fine with XP and as far as I know earlier Window's versions.
However, it won't work with Vista and the message...
Failed to set Data appears.

Code: Select all
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;


with this in the ondestroy event

Code: Select all
if checkbox1.checked then
RunOnStartup('Myprog','C:\folder\Myprog.exe',


Has anyone cured this problem?

Blod
Blod
Junior Member
Junior Member
 
Posts: 33
Joined: June 5th, 2008, 12:54 pm

Postby Kambiz » August 5th, 2008, 9:46 am

Call your function in OnClose or OnCloseQuery event of your form.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2430
Joined: March 7th, 2003, 7:10 pm

Postby Blod » August 5th, 2008, 12:19 pm

My thanks Kambiz
I'll try that.

Blod
Blod
Junior Member
Junior Member
 
Posts: 33
Joined: June 5th, 2008, 12:54 pm

Run Program on Windows startup

Postby Blod » August 5th, 2008, 1:20 pm

Kambiz,

I tried what you said but, unfortunately it isn't working.
And I've tried it on a couple of different computers running Vista.
Any other ideas please?

Blod
Blod
Junior Member
Junior Member
 
Posts: 33
Joined: June 5th, 2008, 12:54 pm

Postby Kambiz » August 5th, 2008, 7:59 pm

I guess it's UAC (User Account Control) of Vista that doesn't let you to write on the registry.

To know whether UAC is respomsible or no, go to Control Panel/User Account/Turn User Account Control on or off and deactivate it.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2430
Joined: March 7th, 2003, 7:10 pm

Run Program on Windows startup

Postby Blod » August 6th, 2008, 3:08 pm

Yes, turning off user account control does solve the problem but of course I can't do that programatically.
So I suppose I'll just have to inform Vista users of my program that they will have to do it manually if they wish

Thanks

Blod
Blod
Junior Member
Junior Member
 
Posts: 33
Joined: June 5th, 2008, 12:54 pm

Postby Kambiz » August 6th, 2008, 8:55 pm

Maybe your users need to have administrative privilege too.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2430
Joined: March 7th, 2003, 7:10 pm

Run Program on Windows startup

Postby Blod » August 7th, 2008, 9:00 am

Yes that would be the answer.

Blod
Blod
Junior Member
Junior Member
 
Posts: 33
Joined: June 5th, 2008, 12:54 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 3 guests

cron