나는 똑같은 문제가 있었지만 위의 대답에도 불구하고 사용자 지정 솔루션으로 끝났으며 사용자와 공유하고 싶습니다.
나는이 방법과
environment.iss
파일을 생성 한 모든
첫째 - 환경의 경로에 경로를 추가 한 변수와 두 번째는 그것을 제거합니다 :
[Code]
const EnvironmentKey = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
procedure EnvAddPath(Path: string);
var
Paths: string;
begin
{ Retrieve current path (use empty string if entry not exists) }
if not RegQueryStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths)
then Paths := '';
{ Skip if string already found in path }
if Pos(';' + Uppercase(Path) + ';', ';' + Uppercase(Paths) + ';') > 0 then exit;
{ App string to the end of the path variable }
Paths := Paths + ';'+ Path +';'
{ Overwrite (or create if missing) path environment variable }
if RegWriteStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths)
then Log(Format('The [%s] added to PATH: [%s]', [Path, Paths]))
else Log(Format('Error while adding the [%s] to PATH: [%s]', [Path, Paths]));
end;
procedure EnvRemovePath(Path: string);
var
Paths: string;
P: Integer;
begin
{ Skip if registry entry not exists }
if not RegQueryStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths) then
exit;
{ Skip if string not found in path }
P := Pos(';' + Uppercase(Path) + ';', ';' + Uppercase(Paths) + ';');
if P = 0 then exit;
{ Update path variable }
Delete(Paths, P - 1, Length(Path) + 1);
{ Overwrite path environment variable }
if RegWriteStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths)
then Log(Format('The [%s] removed from PATH: [%s]', [Path, Paths]))
else Log(Format('Error while removing the [%s] from PATH: [%s]', [Path, Paths]));
end;
참조 : RegQueryStringValue
, RegWriteStringValue
이제 주 .iss 파일에서이 파일을 포함하고 2 개의 이벤트 (문서의 Event Functions 섹션에서 배울 수있는 이벤트에 대한 정보), 설치 후 경로를 추가하는 CurStepChanged
및 CurUninstallStepChanged
사용자가 응용 프로그램을 제거 할 때 제거하십시오.
이
#include "environment.iss"
[Setup]
ChangesEnvironment=true
; More options in setup section as well as other sections like Files, Components, Tasks...
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall
then EnvAddPath(ExpandConstant('{app}') +'\bin');
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usPostUninstall
then EnvRemovePath(ExpandConstant('{app}') +'\bin');
end;
참조가 : ExpandConstant
참고 # 1가 : 설치 단계를 한 번만 경로를 추가합니다 (설치의 재현성을 보장 예제 스크립트가 추가 아래에서/(설치 디렉토리에 상대적)을 bin
디렉토리를 제거).
참고 # 2 : 제거 단계에서는 변수에서 경로가 한 번만 제거됩니다.
보너스 : 확인란을 사용하는 설치 단계 "PATH 변수에 추가".

확인란 와 설치 단계를 추가하려면 "PATH 변수에 추가" (기본적으로 선택) [Tasks]
섹션에서 새 작업을 정의합니다
[Tasks]
Name: envPath; Description: "Add to PATH variable"
그런 다음 당신이 CurStepChanged
이벤트를 확인하실 수 있습니다 :
procedure CurStepChanged(CurStep: TSetupStep);
begin
if (CurStep = ssPostInstall) and IsTaskSelected('envPath')
then EnvAddPath(ExpandConstant('{app}') +'\bin');
end;
간단히 말해서 {olddata }'를 Check 함수에 추가하면 코드에서 값을 다시 읽을 필요가 없습니다. (어쩌면 당신은 할 수 있습니다 - 나는 시도하지 않았습니다);) –
또 다른 것은 경로가있을 수 있지만 다른 대소 문자를 사용하는 것입니다 (쉽게 'UpperCase' 또는 somesuch 함수를 사용하여 수정 됨). 또는 더 나쁘면 8.3 경로 이름을 사용하십시오 (예 : "C : \ Progra ~ 1 \ MyProg") 또는 환경 변수 (예 : "% programfiles % \ MyProg"). 그것들을 탐지하는 것은 악몽 일 것입니다 ... –
프로그램이 제거 될 때 어떨까요? PATH 환경 변수에서 경로를 어떻게 제거 하시겠습니까? –