Discussion:
RunOnStartup fails
(too old to reply)
Stark
2011-01-15 17:04:26 UTC
Permalink
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..)
Stark
2011-01-15 18:38:53 UTC
Permalink
Yes. I disactivated the UAC and it works.
Therefore I tried to request permission for my program creating a .manifest
file and the final MyExe.rec file (following instructions from Internet).
I am getting an error message "Unable to create process" when compiling. Why
?
Where am I supposed to insert the {$R MyP.REC} line ?

Here is what I did:

Forms,
.... in 'Unit1.pas' {Form1};

{$R MyP.REC}
//{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
JJ
2011-01-17 08:22:10 UTC
Permalink
First of all, you should use the proper file extension name for the
resource script file which is "RC" instead of "REC". So that would be
"MyP.RC" instead of "MyP.REC".

And for the compiler directive, use this:
{$R 'MyP.res' 'MyP.RC'}

The MyP.res file will be generated by the compiler and probably
overwriting any existing file.

The directive should be placed between the "unit" and "interface"
statements, but you can put it anywhere outside any block.
Post by Stark
Yes. I disactivated the UAC and it works.
Therefore I tried to request permission for my program creating a
.manifest file and the final MyExe.rec file (following instructions from
Internet).
I am getting an error message "Unable to create process" when compiling.
Why ?
Where am I supposed to insert the {$R MyP.REC} line ?
Forms,
.... in 'Unit1.pas' {Form1};
{$R MyP.REC}
//{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
Stark
2011-01-18 18:21:54 UTC
Permalink
Thnak you for trying to help me.
- The extension name of my resource file is .REC (it results from the
compilation with bcc32.exe of the .RC source file).
- Its purpose should be to raise permission to my program to allow for the
writing of a key into the register.

My program project file looks as follows:

program RunOnWinStartP;
uses
Forms,
RunOnWinStartU in 'RunOnWinStartU.pas' {Form1};

//{$R *.res} // this would be the normal line generated automatically
{$R 'RunOnWinStartP.res' 'RunOnStartUp.REC'} // I changed this line as
you suggested

begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

MainForm exeutes a proc that is intended to write a key into the windows
register. Compilation but still fails with the message "Failed to create
key..." at the following statement:
RegIniFile.WriteString('Software\Microsoft\Windows\CurrentVersion\Run'#0,WindowTitle,
CommandLn);
P E Schoen
2011-01-18 20:39:14 UTC
Permalink
Post by Stark
Thnak you for trying to help me.
- The extension name of my resource file is .REC (it results from the
compilation with bcc32.exe of the .RC source file).
- Its purpose should be to raise permission to my program to allow for the
writing of a key into the register.
MainForm exeutes a proc that is intended to write a key into the
windows register. Compilation but still fails with the message
RegIniFile.WriteString('Software\Microsoft\Windows\CurrentVersion
\Run'#0,WindowTitle, CommandLn);
You might want to look into the following ACL utility, which I use in my
program setup script (InnoSetup):

http://sourceforge.net/projects/setacl/

Here is the line from the .iss file (which in this case prevents Win7 from
virtualizing the AppData folder):

[Run]
Filename: "{tmp}\SetACL.exe";
Parameters: "-on {commonappdata}\Ortmaster
-ot file -actn ace -ace ""n:{username};p:change,write""
-log ""{commonappdata}\Ortmaster\setacl.log"" "

HTH,

Paul
Stark
2011-01-19 23:45:07 UTC
Permalink
Post by Stark
Thnak you for trying to help me.
- The extension name of my resource file is .REC (it results from the
compilation with bcc32.exe of the .RC source file).
- Its purpose should be to raise permission to my program to allow for the
writing of a key into the register.
MainForm exeutes a proc that is intended to write a key into the
windows register. Compilation but still fails with the message
RegIniFile.WriteString('Software\Microsoft\Windows\CurrentVersion
\Run'#0,WindowTitle, CommandLn);
You might want to look into the following ACL utility, which I use in my
program setup script (InnoSetup):

http://sourceforge.net/projects/setacl/

Here is the line from the .iss file (which in this case prevents Win7 from
virtualizing the AppData folder):

[Run]
Filename: "{tmp}\SetACL.exe";
Parameters: "-on {commonappdata}\Ortmaster
-ot file -actn ace -ace ""n:{username};p:change,write""
-log ""{commonappdata}\Ortmaster\setacl.log"" "

HTH,

Paul

Thanks. I downloaded SetACL and had a quick look into it. There are examples
of use, but not in Delphi.. I am afraid I don't have the knowledge for it.
Nevertheless I am going to have a deeper look inti it tomorrow.
P E Schoen
2011-01-20 08:38:14 UTC
Permalink
Post by Stark
Post by P E Schoen
You might want to look into the following ACL utility, which I
http://sourceforge.net/projects/setacl/
Here is the line from the .iss file (which in this case prevents
[Run]
Filename: "{tmp}\SetACL.exe";
Parameters: "-on {commonappdata}\Ortmaster
-ot file -actn ace -ace ""n:{username};p:change,write""
-log ""{commonappdata}\Ortmaster\setacl.log"" "
Post by Stark
Thanks. I downloaded SetACL and had a quick look into it.
There are examples of use, but not in Delphi.. I am afraid I
don't have the knowledge for it. Nevertheless I am going to have a deeper
look inti it tomorrow.
If you also read about UAC and virtualization in Vista and Win7, you will
find lots of information about the concept of "least privilege", which sets
permissions to the lowest level as default. This is understandable in the
Program Files folder (which is actually "Program Files (x86)" for 64 bit
systems), where you normally do not want the user or the application to
modify or write files, but the corresponding "ProgramData" folder is where
one would expect to do that.

The Inno Setup utility is very powerful and it is not only written in
Delphi, but it also incorporates a form of Pascal script. My program has
become complex enough to need a setup file, which copies files to
appropriate places and also performs functions such as file associations
which involve registry changes. The Windows developer forums and knowledge
base suggest that the setup (or install) should take care of these details.
It would be good to have a look at Inno Setup, which can be obtained at:
http://www.jrsoftware.org/isinfo.php

Good luck!

Paul
www.ortmaster.com

Loading...