如何在注册表部分条目中使用Root参数的代码函数?

时间:2013-03-14 17:04:16

标签: inno-setup

我想在用户是管理员时将注册表项设置为HKLM,或者当用户是普通用户时设置HKCU

我试过了:

[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;

但编译器在第一个注册表行返回错误:

Parameter "Root" is not a valid value. 

有关于此的任何建议吗?

1 个答案:

答案 0 :(得分:5)

我认为不可能将函数用作Root参数值getter。我会使用Check这样的条件解决这种情况:

[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;