Issue
If the user runs the installer in admin mode, the system path should be modified and if the installer is run in user mode, then the user environment variable need to me modified.
[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'))
I know HKA
automatically resolves to HKCU
if the installer is in user mode and HKLM
in admin mode, but there is no automatic equivalent for EnvironmentKey
.
Basically something like:
#if "HKA" == "HKCU"
#define EnvironmentKey "Environment"
#else
#define EnvironmentKey "System\CurrentControlSet\Control\Session Manager\Environment"
#endif
Solution
Use a scripted constant:
[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;
Another option is using the Check
parameter:
[Registry]
Root: HKCU; \
Subkey: "Environment"; \
Check: not IsAdminInstallMode; ...
Root: HKLM; \
Subkey: "System\CurrentControlSet\Control\Session Manager\Environment"; \
Check: IsAdminInstallMode; ...
It’s more "code", but no Code
.
Answered By – Martin Prikryl
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0