在Inno Setup的Run条目中运行脚本代码(添加注册表项)而不是可执行文件 [英] Running script code (adding a registry key) instead of executable in Run entry in Inno Setup
问题描述
我要在用户接受密钥添加后添加注册表项. 密钥将告诉Firefox在哪里可以找到我们的插件(存储在app文件夹中)
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)
用户将获得一个与我们要求安装chrome插件" 和安装"的表格相同的复选框是否安装ff插件?" 即插件?" .
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
推荐答案
您可以通过实现NextButtonClick
事件函数,并将可执行文件调用替换为脚本过程调用.
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;
另一种替代方法是添加一个有效但没有操作的[Run]
条目,并使用 BeforeInstall
或AfterInstall
参数调用脚本代码.
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;
我相信您的GetHKLM
逻辑是错误的. Firefox始终写入32位注册表.
I believe that your GetHKLM
logic is wrong. The Firefox always writes to 32-bit registry.
这篇关于在Inno Setup的Run条目中运行脚本代码(添加注册表项)而不是可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!