Environment variable not recognized [unavailable] for [Run] programs in Inno Setup

I have a license.exe file that I call in my installation code at the end,

The code needs an environment variable that must be set before it works,

The code is as follows:

[Registry]
; set PATH
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
    ValueType: string; ValueName: "PATH"; ValueData: "{app}"

[Setup]
; Tell Windows Explorer to reload the environment
ChangesEnvironment=yes

[Run]
Filename: "{app}\temp\installation_files\license.exe";

Here the code is executed, but does not find the correct path.

When I check the system environment variable, it is set correctly,

When I run the code license.exeafter that manually, it works correctly and sees the environment variable.

Can someone tell me how to fix this?

Or how to delay a partition [Run]until the system recognizes an environment variable?

+4
source share
2

, [Run], , . , . : script:

[Run]
Filename: "{app}\temp\installation_files\license.exe"; BeforeInstall: SetEnvPath

[Code]
#ifdef UNICODE
  #define AW "W"
#else
  #define AW "A"
#endif
function SetEnvironmentVariable(lpName: string; lpValue: string): BOOL;
  external 'SetEnvironmentVariable{#AW}@kernel32.dll stdcall';

procedure SetEnvPath;
begin
  if not SetEnvironmentVariable('PATH', ExpandConstant('{app}')) then
    MsgBox(SysErrorMessage(DLLGetLastError), mbError, MB_OK);
end;

:

@Jerry , [Run]. , , .

, [Run], . RefreshEnvironment Inno script. , ChangesEnvironment, yes.

script ChangesEnvironment RefreshEnvironment AfterInstall :

[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
    ValueType: string; ValueName: "PATH"; ValueData: "{app}"; \
    AfterInstall: RefreshEnvironment;

[Run]
Filename: "{app}\temp\installation_files\license.exe";

[Code]
const
  SMTO_ABORTIFHUNG = 2;
  WM_WININICHANGE = $001A;
  WM_SETTINGCHANGE = WM_WININICHANGE;

type
  WPARAM = UINT_PTR;
  LPARAM = INT_PTR;
  LRESULT = INT_PTR;

function SendTextMessageTimeout(hWnd: HWND; Msg: UINT;
  wParam: WPARAM; lParam: PAnsiChar; fuFlags: UINT;
  uTimeout: UINT; out lpdwResult: DWORD): LRESULT;
  external 'SendMessageTimeoutA@user32.dll stdcall';  

procedure RefreshEnvironment;
var
  S: AnsiString;
  MsgResult: DWORD;
begin
  S := 'Environment';
  SendTextMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
    PAnsiChar(S), SMTO_ABORTIFHUNG, 5000, MsgResult);
end;
+7

SetEnvironmentVariable TLama .

[Run] runasoriginaluser flag ( postinstall flag). , " " "".

, runasoriginaluser Inno Setup. SetEnvironmentVariable , . , (imo).

, runasoriginaluser, , .

cmd.exe set :

[Run]
Filename: "{cmd}"; Parameters: "/C set MYVAR=MyValue & ""{app}\MyProg.exe"""; \
    Description: "Run My Program"; Flags: postinstall runhidden

runhidden flag cmd.exe, ( , ). , start, () .

+2

Source: https://habr.com/ru/post/1526389/


All Articles