使用 Inno Setup 的条件注册表项
Conditional Registry entries with Inno Setup
如果满足两个条件,我希望写入一些注册表项:
- 安装程序运行处于静默模式并且
- 我有一些命令行参数。
在 [Registry]
部分有没有办法做到这一点?
我在 [Run]
部分有类似的内容:
Filename: "{app}\AppWithParams.exe"; Parameters: "{code:BuildParams}"; \
Flags: postinstall skipifsilent; \
Description: "This program needs some parameters"
[Code]
function BuildParams(Param: string): string;
begin
Result := Format('/p1="%s" /p2="%s" /p3="%s"', [
ExpandConstant('{param:p1|}'),
ExpandConstant('{param:p2|}'),
ExpandConstant('{param:p3|}')]);
end;
我看到 [Registry]
条目可以依赖于 [Task]
,但我只在静默模式下需要它们,所以我认为这种方法不适合我。
[Registry]
Root: HKLM; Subkey: "Software\My Company"; Check: ShouldCreateRegistry
[Code]
function ShouldCreateRegistry: Boolean;
begin
Result := WizardSilent and CmdLineParamExists('/CreateRegistry');
end;
-
WizardSilent
是 built-in。
- 对于
CmdLineParamExists
,参见 Is it possible to accept custom command line parameters with Inno Setup。
如此琐碎的Check
函数实际上可以内联:
[Registry]
Root: HKLM; Subkey: "Software\My Company"; \
Check: WizardSilent and CmdLineParamExists('/CreateRegistry')
如果满足两个条件,我希望写入一些注册表项:
- 安装程序运行处于静默模式并且
- 我有一些命令行参数。
在 [Registry]
部分有没有办法做到这一点?
我在 [Run]
部分有类似的内容:
Filename: "{app}\AppWithParams.exe"; Parameters: "{code:BuildParams}"; \
Flags: postinstall skipifsilent; \
Description: "This program needs some parameters"
[Code]
function BuildParams(Param: string): string;
begin
Result := Format('/p1="%s" /p2="%s" /p3="%s"', [
ExpandConstant('{param:p1|}'),
ExpandConstant('{param:p2|}'),
ExpandConstant('{param:p3|}')]);
end;
我看到 [Registry]
条目可以依赖于 [Task]
,但我只在静默模式下需要它们,所以我认为这种方法不适合我。
[Registry]
Root: HKLM; Subkey: "Software\My Company"; Check: ShouldCreateRegistry
[Code]
function ShouldCreateRegistry: Boolean;
begin
Result := WizardSilent and CmdLineParamExists('/CreateRegistry');
end;
-
WizardSilent
是 built-in。 - 对于
CmdLineParamExists
,参见 Is it possible to accept custom command line parameters with Inno Setup。
如此琐碎的Check
函数实际上可以内联:
[Registry]
Root: HKLM; Subkey: "Software\My Company"; \
Check: WizardSilent and CmdLineParamExists('/CreateRegistry')