Innosetup SendMessage after changing the environment values

与世无争的帅哥 提交于 2020-01-04 01:29:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!