Inno Setup Query-使用[Registry]部分向Registry添加路径

时间:2011-01-17 08:12:46

标签: registry inno-setup

问题是当我使用{olddata};{app}\Lib\RAD2009"将新路径附加到旧数据(路径)时,它会创建重复条目。

代码:

Root: HKCU; Subkey: Software\CodeGear\BDS\6.0\Library; ValueType: string; ValueName: Search Path; ValueData: "{olddata};{app}\Lib\RAD2009"; Flags: dontcreatekey; Tasks: RAD2009

同样,我正在写这条路,即{app}\Lib\RAD2009在注册表中的另一个地方。

Library Path

另外我想将路径“{app} \ Lib \ RAD2009”附加到{olddata}并在卸载时,我只想删除“{app} \ Lib \ RAD2009”而不是{olddata} < / p>

提前致谢。

1 个答案:

答案 0 :(得分:3)

http://code.haskell.org/gtk2hs/tools/win32/gtk2hs.iss显示

[Registry]
Root: HKCU; Subkey: "Environment"; ValueName: "Path"; ValueType: "string"; ValueData: "{app}\bin;{olddata}"; Check: NotOnPathAlready(); Flags: preservestringtype;

[Code]
function NotOnPathAlready(): Boolean;
var
  BinDir, Path: String;
begin
  Log('Checking if Gtk2Hs\bin dir is already on the %PATH%');
  if RegQueryStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', Path) then
  begin // Successfully read the value
    Log('HKCU\Environment\PATH = ' + Path);
    BinDir := ExpandConstant('{app}\bin');
    Log('Looking for Gtk2Hs\bin dir in %PATH%: ' + BinDir + ' in ' + Path);
    if Pos(LowerCase(BinDir), Lowercase(Path)) = 0 then
    begin
      Log('Did not find Gtk2Hs\bin dir in %PATH% so will add it');
      Result := True;
    end
    else
    begin
      Log('Found Gtk2Hs bin dir in %PATH% so will not add it again');
      Result := False;
    end
  end
  else // The key probably doesn't exist
  begin
    Log('Could not access HKCU\Environment\PATH so assume it is ok to add it');
    Result := True;
  end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
  BinDir, Path: String;
begin
  if (CurUninstallStep = usPostUninstall)
     and (RegQueryStringValue(HKEY_CURRENT_USER, 'Environment', 'PATH', Path)) then
  begin
    BinDir := ExpandConstant('{app}\bin');
    if Pos(LowerCase(BinDir) + ';', Lowercase(Path)) <> 0 then
    begin
      StringChange(Path, BinDir + ';', '');
      RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', 'PATH', Path);
    end;
  end;
end;

小心尾随/领先;