Inno Setup ChangeEnvironment 不起作用

Inno Setup ChangeEnvironment 不起作用

我正在使用 InnoSetup 创建安装程序,但安装后环境未刷新。用户必须重新启动计算机才能刷新环境变量。

这是我的代码,任何帮助都将不胜感激。

    [Setup]
ChangesEnvironment = yes
AppName=ffmpeg
AppId=ffmpeg
AppVerName=ffmpeg
DefaultDirName={pf}\ffmpeg
DefaultGroupName=ffmpeg

SourceDir=c:/Users/pkallonis/Desktop/ffmpeg_installer/ffmpeg
OutputDir=c:/Users/pkallonis/Desktop/ffmpeg_installer
OutputBaseFilename = ffmpeg-win32-setup

DisableProgramGroupPage = yes
Compression=lzma
SolidCompression=yes


[Files]
Source: "*.*"; DestDir: "{app}";

; the code below is to append to the path and remove on uninstalling
; to put off, comment the two functions at the end

[Code]
function Replace(Dest, SubStr, Str: string): string;
var
  Position: Integer;
  Ok: Integer;
begin
  Ok := 1;
  while Ok > 0 do
  begin
    Position:=Pos(SubStr, Dest);
    if Position > 0 then
    begin
      Delete(Dest, Position, Length(SubStr));
      Insert(Str, Dest, Position);
    end else
      Ok := 0;
  end
  Result:=Dest;
end;

procedure AppendToPath();
var
  V: string;
  Str: string;
begin
  RegQueryStringValue(HKLM, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', V)
  Str := ExpandConstant('{app}');
  V := Replace(V, Str, '');
  V := V + ';' + Str;
  V := Replace(V,';;',';');
  RegWriteStringValue(HKLM, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', V)

 // MsgBox(V, mbInformation, MB_OK); 
end;

procedure RemoveFromPath();
var
  V: string;
  Str: string;
begin
  RegQueryStringValue(HKLM, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', V)
  Str := ExpandConstant('{app}');
  V := Replace(V, Str, '');
  V := Replace(V,';;',';');
  RegWriteStringValue(HKLM, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', V)
  //MsgBox(V, mbInformation, MB_OK);
end;

procedure DeinitializeSetup();
begin
  AppendToPath();
end;

procedure DeinitializeUninstall();
begin
  RemoveFromPath();
end;

答案1

我遇到了同样的问题,并使用将 [Setup]ChangesEnvironment 变量设置为是来解决它的,并且成功了

http://www.jrsoftware.org/ishelp/index.php?topic=setup_changesenvironment

相关内容