I set environment variable in the registry using InnoSetup:
[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; ValueName: "MY_PROGRAM_HOME_DIR"; ValueData: "{app}"
But system cannot see this variable until I call SendMessage
.
[Code]
procedure DeinitializeSetup();
begin
// HWND_BROADCAST = $FFFF
// WM_SETTINGCHANGE = $001A
SendMessage($FFFF, $001A, 0, Longint(PChar('Environment')));
end;
InnoSetup says:
... Column 60: Type mismatch
How do I correctly typecast PChar
into Longint
in InnoSetup script?
Use the ChangesEnvironment
directive instead of doing the same from your script code. From the reference:
When set to yes, at the end of the installation Setup will notify other running applications (notably Windows Explorer) that they should reload their environment variables from the registry.
In InnoSetup, when you use the above directive, the following code is called inside:
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
LPARAM(PChar('Environment')), SMTO_ABORTIFHUNG, 5000, MsgResult);
Use the ChangesEnvironment
Work fine for me.
Ex:
[Setup]
ChangesEnvironment=yes
Be careful: The broadcast message occur before the call of 'DeinitializeSetup'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With