How do I modify the PATH environment variable when running an Inno Setup Installer?

后端 未结 6 602
逝去的感伤
逝去的感伤 2020-11-28 03:31

Inno Setup lets you set environment variables via the [Registry] sections (by setting registry key which correspond to environment variable)

However, sometimes you d

6条回答
  •  自闭症患者
    2020-11-28 04:03

    The NeedsAddPath in the answer by @mghie doesn't check trailing \ and letter case. Fix it.

    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;
    

提交回复
热议问题