根据安装程序处于用户模式还是管理员模式更改环境注册表项

问题描述 投票:0回答:1

如果用户在管理员模式下运行安装程序,则需要修改系统路径,如果安装程序在用户模式下运行,则需要修改用户环境变量。

[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
windows installation registry inno-setup
1个回答
1
投票

使用脚本常量

[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

© www.soinside.com 2019 - 2024. All rights reserved.