问题
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?
回答1:
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);
回答2:
Use the ChangesEnvironment
Work fine for me.
Ex:
[Setup]
ChangesEnvironment=yes
Be careful: The broadcast message occur before the call of 'DeinitializeSetup'
来源:https://stackoverflow.com/questions/12550791/innosetup-sendmessage-after-changing-the-environment-values