Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Innosetup SendMessage after changing the environment values

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?

like image 969
barbaris Avatar asked Sep 23 '12 08:09

barbaris


2 Answers

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);
like image 152
TLama Avatar answered Oct 20 '22 04:10

TLama


Use the ChangesEnvironment

Work fine for me.

Ex:

[Setup]
ChangesEnvironment=yes

Be careful: The broadcast message occur before the call of 'DeinitializeSetup'

like image 41
Stéphane Millien Avatar answered Oct 20 '22 03:10

Stéphane Millien