การตั้งค่า Inno เปลี่ยนสภาพแวดล้อมไม่ทำงาน


2

ฉันใช้ 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;

คำตอบ:


โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.