PDA

View Full Version : LaunchApplication not picking up environment



readshaw
10-18-2010, 04:57 AM
I am in the process of migrating an InstallShield 2010 project to InstallShield 2011. The project includes a custom action implemented using InstallScript in order to set some special environment variables before launching an application. The InstallScript includes code similar to:

...
SetEnvironmentVariable("VARIABLE_NAME", INSTALLDIR);
LaunchApplication(<path to app>, "", svAppPath, SW_HIDE, 0, LAAW_OPTION_NOWAIT);
...

With InstallShield 2010, the environment variable value set above is picked up by the application specified in LaunchApplication(). With InstallShield 2011, the environment is not picked up. The executable is still launched successfully, but functions incorrectly because the environment variable is not set.

Any ideas why this may have changed between releases?

Is there another approach that could be used to achieve the same outcome.

Thanks,
Neil.

rrinblue22
10-18-2010, 01:15 PM
You can still get the LaunchApp working in the meanwhile.
try to use INSTALLDIR ^ something instead of the Environment variable

readshaw
10-18-2010, 04:34 PM
It turns out this was related to a change between 2010 and 2011 to default to Unicode versions of Windows APIs. I changed 'SetEnvironmentVariable' to 'SetEnvironmentVariableA' and things worked as they did before the migration.

joshstechnij
10-19-2010, 12:00 PM
Since SetEnvironmentVariable is not prototyped in any InstallScript headers, the prototype being used needs to be updated to work correctly with Unicode (calling SetEnvironmentVariable with no explicit thunk (A/W) will result in the W version being called by the engine). For example, if the prototype was this before IS 2011:
prototype NUMBER KERNEL32.SetEnvironmentVariable(string, string);

Calling the Unicode (W) version of this API will not work with 'string' parameters. The prototype needs to be updated to work with Unicode parameters:
prototype NUMBER KERNEL32.SetEnvironmentVariable(wstring, wstring);

Using 'wstring' as the parameter types will tell the InstallScript engine to marshal string parameters by Unicode instead of ANSI.

Further information regarding Unicode changes in InstallScript are documented in the Upgrading Projects to InstallShield 2011 (http://kb.flexerasoftware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&externalId=Q208911&sliceId=) article.