How to use code function for Root parameter in Registry section entry?
inno-setup
Solution
I don't think it's possible to use function as a `Root` parameter value getter. I'd workaround this situation by using `Check` condition like this:
[Registry]
Root: HKCU; Subkey: "Software\MyCompany\MySW\Settings"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"; Check: IsRegularUser
Root: HKLM; Subkey: "Software\MyCompany\MySW\Settings"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"; Check: not IsRegularUser
[Code]
function IsRegularUser: Boolean;
begin
Result := not (IsAdminLoggedOn or IsPowerUserLoggedOn);
end;
Problem
I would like to set a registry key to `HKLM` when user is an administrator or `HKCU` when user is a normal user. I tried this: ``` [Registry] Root: "{code:DefRegRoot}"; Subkey: "Software\MyCompany\MySW\Settings"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}" [Code] function IsRegularUser(): Boolean; begin Result := not (IsAdminLoggedOn or IsPowerUserLoggedOn); end; function DefRegRoot(Param: String): String; begin if IsRegularUser then Result := HKCU else Result := HKLM; end; ``` But the compiler returns an error on the first Registry line: ``` Parameter "Root" is not a valid value. ``` Any suggestion about this ?