I am using InnoSetup to create an installer but the Environment is not refreshed after the installation. The user has to restart the computer in order for the Environmental Variable to be refreshed.
This is my code any help will be appreciated.
[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;