问题
I want to add a registry key after the user accept the key addition. The key will tell Firefox where to find our plugin (which is stored in the app folder)
The user will get a checkbox "install ff plug-in?" in the same form as where we ask "install chrome plugin" and "install ie plugin?".
[Code]
function GetHKLM: Integer;
begin
if IsWin64 then
Result := HKLM64
else
Result := HKLM32;
end;
function CheckForMozilla: Boolean;
begin
Result := False;
if RegKeyExists(GetHKLM(), 'SOFTWARE\Mozilla\Mozilla Firefox') then
begin
Result := True;
end;
if RegKeyExists(GetHKLM(), 'SOFTWARE\Mozilla\Firefox') then
begin
Result := True;
end;
end;
function AddFFKey : Boolean;
begin
{ Some way to write this key in code section : }
GetHKLM() + '\SOFTWARE\Mozilla\Mozilla Firefox\extensions\5e12c5a...'
end;
[Run]
Filename: AddFFKey; Flags: runascurrentuser postinstall ; \
Check: CheckForMozilla; Description: "Install firefox plug-in"
Thank you all!
Steve
回答1:
You can capture the Finish button click by implementing NextButtonClick event function and replace the executable call with a script procedure call.
#define InstallFFPluginDesc "Install firefox plug-in"
[Run]
FileName: "fake.exe"; Flags: postinstall; Description: "{#InstallFFPluginDesc}"; \
Check: CheckForMozilla
[Code]
procedure AddFFKey;
begin
Log('Adding FF key');
RegWriteStringValue(
GetHKLM(), 'SOFTWARE\Mozilla\Mozilla Firefox\extensions\5e12c5a...', ...);
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
Index: Integer;
begin
if CurPageID = wpFinished then
begin
{ When restart is needed, the RunList is never populated/shown. }
if WizardForm.RunList.Items.Count > 0 then
begin
{ Find the RunList entry for the FF plugin }
Index := WizardForm.RunList.Items.IndexOf('{#InstallFFPluginDesc}');
{ Does it exist and is it checked? }
if (Index >= 0) and WizardForm.RunList.Checked[Index] then
begin
{ Uncheck, so that the fake.exe is not run }
WizardForm.RunList.Checked[Index] := False;
{ Do our scripted action instead }
AddFFKey;
end;
end;
end;
Result := True;
end;
Another alternative is to add a working but noop [Run]
entry, and use BeforeInstall or AfterInstall parameter to call your script code.
It's easier and more robust solution, just with a side-effect (you have to run some process, even though it does not need to do anything).
[Run]
FileName: "{cmd}"; Parameters: "/C echo noop"; Flags: postinstall runhidden; \
Description: "Install firefox plug-in"; Check: CheckForMozilla; \
BeforeInstall: AddFFKey
[Code]
procedure AddFFKey;
begin
Log('Adding FF key');
...
end;
I believe that your GetHKLM
logic is wrong. The Firefox always writes to 32-bit registry.
来源:https://stackoverflow.com/questions/34007625/running-script-code-adding-a-registry-key-instead-of-executable-in-run-entry-i