Super User Asked by user3812737 on February 10, 2021
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, 'SYSTEMCurrentControlSetControlSession ManagerEnvironment', 'Path', V)
Str := ExpandConstant('{app}');
V := Replace(V, Str, '');
V := V + ';' + Str;
V := Replace(V,';;',';');
RegWriteStringValue(HKLM, 'SYSTEMCurrentControlSetControlSession ManagerEnvironment', 'Path', V)
// MsgBox(V, mbInformation, MB_OK);
end;
procedure RemoveFromPath();
var
V: string;
Str: string;
begin
RegQueryStringValue(HKLM, 'SYSTEMCurrentControlSetControlSession ManagerEnvironment', 'Path', V)
Str := ExpandConstant('{app}');
V := Replace(V, Str, '');
V := Replace(V,';;',';');
RegWriteStringValue(HKLM, 'SYSTEMCurrentControlSetControlSession ManagerEnvironment', 'Path', V)
//MsgBox(V, mbInformation, MB_OK);
end;
procedure DeinitializeSetup();
begin
AppendToPath();
end;
procedure DeinitializeUninstall();
begin
RemoveFromPath();
end;
I faced the same problem and solved it using the [Setup]ChangesEnvironment variable set to yes and it did the trick
http://www.jrsoftware.org/ishelp/index.php?topic=setup_changesenvironment
Answered by Binbin on February 10, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP