INNO and Environment Variables

1,137 views
Skip to first unread message

David Fileccia

unread,
Jul 6, 2021, 4:28:19 PM7/6/21
to inno...@googlegroups.com

Hi,

 

I am trying to launce the program I just installed and it requires one environment variable. I set the environment variable in my install script, I set the variable in the “BeforeInstall:” section of my run command and I also issue a “refresh” of the environment.

 

As far as I can debug, the variable gets set properly using the following code:

[Code]

#ifdef UNICODE

   #define AW "W"

#else

   #define AW "A"

#endif

 

function SendTextMessageTimeout (hWnd : HWND; Msg : UINT; wParam : WPARAM; lParam : PAnsiChar;

      fuFlags : UINT; uTimeout : UINT; out lpdwResult : DWORD) : LRESULT;

   external 'SendMessageTimeout{#AW}@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;

 

function SetEnvironmentVariable (lpName : String; lpValue : String) : Boolean;

   external 'SetEnvironmentVariable{#AW}@kernel32.dll stdcall';

 

procedure SetDataPathEnv;

begin

   SetEnvironmentVariable ('I3K_DATAPATH', ExpandConstant ('{#MyJobDst}'));

   RefreshEnvironment;

end;

 

[Run]

Filename: "{app}\{#MyAppName}.exe"; Parameters: "{code:MyParameters}"; Description: "Launch {#MyAppName}"; BeforeInstall: SetDataPathEnv; Flags: nowait postinstall skipifsilent

 

 

The app will launch but it tells me the environment is not set. This only happens for the first install because the value has not been set yet.

 

Are there any known ways to solve this problem? It would be nice to launch the app for our customers.

 

Best Regards,

 

David Fileccia

Senior Systems Engineer | HEMISPHERE GNSS

Office: 6860 Little Twin Road, Germantown, OH 45327, USA

Corporate: 8515 E. Anderson Drive, Scottsdale, AZ 85255, USA

M: +1 404 579 4391

dfil...@hgnss.com | www.hgnss.com

 

Disclaimer: This message (including any other messages, attachments, or files within) contains information that may be confidential or privileged and is the property of Hemisphere GNSS, Inc. and its subsidiaries (‘Hemisphere’). It is intended for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, copy, distribute, print, retain, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. Any opinions or views expressed within are solely those of the author and do not necessarily represent those of Hemisphere. Thank you for your cooperation.

 

Bill Stewart

unread,
Jul 8, 2021, 1:56:10 PM7/8/21
to innosetup
On Tuesday, July 6, 2021 at 2:28:19 PM UTC-6 David Fileccia wrote:

Hi,

I am trying to launce the program I just installed and it requires one environment variable. I set the environment variable in my install script, I set the variable in the “BeforeInstall:” section of my run command and I also issue a “refresh” of the environment.

As far as I can debug, the variable gets set properly using the following code:

...
[Run]
Filename: "{app}\{#MyAppName}.exe"; Parameters: "{code:MyParameters}"; Description: "Launch {#MyAppName}"; BeforeInstall: SetDataPathEnv; Flags: nowait postinstall skipifsilent

The app will launch but it tells me the environment is not set. This only happens for the first install because the value has not been set yet.

Are there any known ways to solve this problem? It would be nice to launch the app for our customers.

Best Regards,

David Fileccia

Senior Systems Engineer | HEMISPHERE GNSS

See the Windows documentation for the SetEnvironmentVariable Windows API call:


Note the description of the function: "Sets the contents of the specified environment variable for the current process."

Also note the sentence in the Remarks section: "This function has no effect on the system environment variables or the environment variables of other processes."

In other words this function is not going to make an environment variable appear system-wide. It will only set the variable in the current process (i.e., the installer that's running). When the installer finishes, the variable will disappear.

Instead, I would recommend taking a look at the Inno Setup FAQ, which has a heading about this:


Bill

Jernej Simončič

unread,
Jul 8, 2021, 4:29:47 PM7/8/21
to Bill Stewart on [innosetup]

On Thursday, July 8, 2021, 19:56:10, Bill Stewart wrote:


Also note the sentence in the Remarks section: "This function has no effect on the system environment variables or the environment variables of other processes."

I think the problem here is that while SetEnvironmentVariable will set the environment for the current process and all children started from the current process, Inno does not start [Run] entries (other than those with runascurrentuser flag) from the same process that runs [Code], so those environment changes will not be visible.


-- 
< Jernej Simončič ><><><><>< https://eternallybored.org/ >


Never decide to buy something while listening to the salesman.
       -- Berkeley's Third Law

Martijn Laan

unread,
Jul 9, 2021, 2:16:55 AM7/9/21
to inno...@googlegroups.com
Also the code is wrong, it sends an Ansi string to a Unicode function.

Greetings,
Martijn

> Op 8 jul. 2021 om 22:29 heeft Jernej Simončič <jernej|s-g....@eternallybored.org> het volgende geschreven:
> --
> You received this message because you are subscribed to the Google Groups "innosetup" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to innosetup+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/innosetup/1315364238.20210708222943%40eternallybored.org.
Reply all
Reply to author
Forward
0 new messages