我想在用户是管理员时将注册表项设置为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.
有关于此的任何建议吗?
答案 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;