如果用户在管理员模式下运行安装程序,则需要修改系统路径,如果安装程序在用户模式下运行,则需要修改用户环境变量。
[Registry]
; If user installation mode
#define EnvironmentRootKey "HKCU"
#define EnvironmentKey "Environment"
; If admin mode
#define EnvironmentRootKey "HKLM"
#define EnvironmentKey "System\CurrentControlSet\Control\Session Manager\Environment"
Root: {#EnvironmentRootKey}; Subkey: "{#EnvironmentKey}"; ValueType: expandsz; \
ValueName: "Path"; ValueData: "{olddata};{app}\bin"; Tasks: addtopath; \
Check: NeedsAddPath(ExpandConstant('{app}\bin'))
我知道,如果安装程序处于用户模式,
HKA
会自动解析为 HKCU
,而 HKLM
处于管理模式,但 EnvironmentKey
没有自动等效项。
基本上是这样的:
#if "HKA" == "HKCU"
#define EnvironmentKey "Environment"
#else
#define EnvironmentKey "System\CurrentControlSet\Control\Session Manager\Environment"
#endif
使用脚本常量:
[Registry]
Root: HKA; Subkey: "{code:GetEnvironmentKey}"; ...
[Code]
function GetEnvironmentKey(Param: string): string;
begin
if IsAdminInstallMode then
Result := 'System\CurrentControlSet\Control\Session Manager\Environment'
else
Result := 'Environment';
end;
Check
参数:
[Registry]
Root: HKCU; \
Subkey: "Environment"; \
Check: not IsAdminInstallMode; ...
Root: HKLM; \
Subkey: "System\CurrentControlSet\Control\Session Manager\Environment"; \
Check: IsAdminInstallMode; ...
更多的是“代码”,但没有
Code
。