0

If i uninstall the program the wohle System "Path" entry gets deleted instead of the created Registry value: "C:\Program Files (x86)\MyProg" , how can i change this?

Here is my Inno Setup script:

[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
    ValueType: expandsz; ValueName: "PATH"; ValueData: "{olddata};{app}"; Flags: uninsdeletekey \
    Check: NeedsAddPath(ExpandConstant('{app}'))

[Code]
function NeedsAddPath(Param: string): boolean;
var
  OrigPath: string;
begin
  if not RegQueryStringValue(
    HKEY_LOCAL_MACHINE,
    'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
    'Path', OrigPath)
  then begin
    Result := True;
    exit;
  end;
  { look for the path with leading and trailing semicolon }
  { Pos() returns 0 if not found }
  Result :=
    (Pos(';' + UpperCase(Param) + ';', ';' + UpperCase(OrigPath) + ';') = 0) and
    (Pos(';' + UpperCase(Param) + '\;', ';' + UpperCase(OrigPath) + ';') = 0); 
end;
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
K3V1991
  • 1
  • 1
  • See [How do I modify the PATH environment variable when running an Inno Setup Installer?](https://stackoverflow.com/q/3304463/850848) and [Inno Setup - Remove path from PATH environment variable while uninstalling a program](https://stackoverflow.com/q/35410421/850848). – Martin Prikryl Apr 20 '20 at 11:28
  • Once again, see [Remove path from PATH environment variable while uninstalling a program](https://stackoverflow.com/q/35410421/850848). – Martin Prikryl Apr 20 '20 at 15:29
  • I need help, the link doesnt help – K3V1991 Apr 20 '20 at 16:41
  • *"doesnt help"* doesn't help us understanding what problem do you have. – We need [mcve]. – Martin Prikryl Apr 20 '20 at 16:43
  • Im a total noob in inno setup. If i uninstall the App my "Path" gets completly deleted and i have no clue how to do it right – K3V1991 Apr 20 '20 at 16:49
  • Did you remove the `uninsdeletekey` flag? – Martin Prikryl Apr 20 '20 at 16:51
  • Yes - please omit the `uninsdeletekey` flag from your code. That will delete the `Environment` subkey from your registry - something you definitely should _not_ be doing. (I for one would be annoyed, to put it mildly, if uninstalling a program deleted all of my environment variables.) – Bill_Stewart Apr 20 '20 at 20:03

0 Answers0