0

The problem is when i am appending the new path to the old data(paths) using {olddata};{app}\Lib\RAD2009", It creates duplicate entry.

Code:

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

Similary, I am writting this path i.e. {app}\Lib\RAD2009 at one more place in registry.

Library Path

And Also I want to append the path "{app}\Lib\RAD2009" to the {olddata} and while uninstalling, I want to delete only the "{app}\Lib\RAD2009" and not {olddata}

Thanks in advance.

user578219
  • 597
  • 2
  • 9
  • 32
  • I tried your Code and InnoSetup added the value correctly until I ran it a second time without uninstalling. If the value being added already exists, and the setup is run again, I see the value added a second time. As far as removing the value on uninstall, you'll need to read the registry value, removing the value you want, then re-write it back out. I don't have any code for that though. – mirtheil Jan 17 '11 at 14:38
  • Thanks Mirtheil for the answer...yes it adds the path second time as I have not given the flag "uninsdeletevalue" while uninstalling because if I give that it would delete all the paths while uninstalling. So is there some way by which I can delete only the path while uninstalling and not all the paths({olddata})... – user578219 Jan 19 '11 at 13:19
  • Somewhat similar to http://stackoverflow.com/questions/3304463/how-do-i-modify-the-path-environment-variable-when-running-an-inno-setup-install – Kevin Smyth Oct 18 '11 at 20:36

1 Answers1

3

http://code.haskell.org/gtk2hs/tools/win32/gtk2hs.iss shows

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

Be careful with trailing/leading ;.

Kevin Smyth
  • 1,892
  • 21
  • 22