Page 1 of 1

Run Program on Windows startup

PostPosted: August 4th, 2008, 2:59 pm
by Blod
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

PostPosted: August 5th, 2008, 9:46 am
by Kambiz
Call your function in OnClose or OnCloseQuery event of your form.

PostPosted: August 5th, 2008, 12:19 pm
by Blod
My thanks Kambiz
I'll try that.

Blod

Run Program on Windows startup

PostPosted: August 5th, 2008, 1:20 pm
by Blod
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

PostPosted: August 5th, 2008, 7:59 pm
by Kambiz
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.

Run Program on Windows startup

PostPosted: August 6th, 2008, 3:08 pm
by Blod
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

PostPosted: August 6th, 2008, 8:55 pm
by Kambiz
Maybe your users need to have administrative privilege too.

Run Program on Windows startup

PostPosted: August 7th, 2008, 9:00 am
by Blod
Yes that would be the answer.

Blod