Stark
2011-01-15 17:04:26 UTC
I found this proc to register a program to run at startup, but execution
fails with the message "Failed to create key
Software\Microsoft\CurrentVersion\Run". Here is the execution statement:
RunOnStartUp('Calculator', 'C:\Windows\System32\calc.exe', False);
procedure RunOnStartup(WindowTitle,CommandLn: String; RunOnlyOnce: Boolean);
var
RegIniFile : TRegIniFile;
begin
RegIniFile := TRegIniFile.Create('');
with RegIniFile do begin
RootKey := HKEY_LOCAL_MACHINE;
if RunOnlyOnce then
RegIniFile.WriteString('Software\Microsoft\Windows\' +
'CurrentVersion\RunOnce'#0,
WindowTitle, CommandLn)
else
RegIniFile.WriteString('Software\Microsoft\Windows\' +
'CurrentVersion\Run'#0,
WindowTitle, CommandLn);
Free;
end;
end;
I made small changes (TRegistry in place of TRegIniFile..) and now it fails
with "Failed to set data for Calculator.
Any idea on why ? I run Delphi2007 in Win Vista. May be something to do with
authorizations (but I can edit the registry manually..)
fails with the message "Failed to create key
Software\Microsoft\CurrentVersion\Run". Here is the execution statement:
RunOnStartUp('Calculator', 'C:\Windows\System32\calc.exe', False);
procedure RunOnStartup(WindowTitle,CommandLn: String; RunOnlyOnce: Boolean);
var
RegIniFile : TRegIniFile;
begin
RegIniFile := TRegIniFile.Create('');
with RegIniFile do begin
RootKey := HKEY_LOCAL_MACHINE;
if RunOnlyOnce then
RegIniFile.WriteString('Software\Microsoft\Windows\' +
'CurrentVersion\RunOnce'#0,
WindowTitle, CommandLn)
else
RegIniFile.WriteString('Software\Microsoft\Windows\' +
'CurrentVersion\Run'#0,
WindowTitle, CommandLn);
Free;
end;
end;
I made small changes (TRegistry in place of TRegIniFile..) and now it fails
with "Failed to set data for Calculator.
Any idea on why ? I run Delphi2007 in Win Vista. May be something to do with
authorizations (but I can edit the registry manually..)