Run Program As - Environment parameter questions

Got a problem you cannot solve? Try here.
BobRoush
Posts: 27
Joined: Sat Aug 26, 2006 12:26 pm

Run Program As - Environment parameter questions

Postby BobRoush » Mon Oct 02, 2006 12:06 pm

The help text says...
Environment
If you wish to pass any environment variables to the program, or override any pre-defined variable values, enter them in this field.

What is the format for passing 1 environment variable?
What is the format for passing more than 1 environment variable?

What is the format for passing 1 environment variable, overriding any pre-defined variable value?
What is the format for passing more than 1 environment variable, overriding any pre-defined variable values?

MichaelNesmith
Posts: 3452
Joined: Thu Dec 22, 2005 7:17 pm
Contact:

Postby MichaelNesmith » Mon Oct 02, 2006 8:42 pm

Bob,

The format is identical to the one used by the lpEnvironment parameter of the CreateProcess function. You can look this up in the Platform SDK.
Michael Nesmith
InstallAware
Home of The Next Generation MSI Installer
Get your free copy today - http://www.installaware.com/

BobRoush
Posts: 27
Joined: Sat Aug 26, 2006 12:26 pm

Postby BobRoush » Tue Oct 03, 2006 4:47 am

this link, <http://windowssdk.msdn.microsoft.com/en-us/library/ms682425.aspx>, says
CreateProcess
Creates a new process and its primary thread. ...
BOOL WINAPI CreateProcess(
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);
Parameters
...
lpEnvironment
[in] A pointer to the environment block for the new process. If this parameter is NULL, the new process uses the environment of the calling process.
An environment block consists of a null-terminated block of null-terminated strings. Each string is in the form:
name=value
Because the equal sign is used as a separator, it must not be used in the name of an environment variable.
...
Note that an ANSI environment block is terminated by two zero bytes: one for the last string, one more to terminate the block. A Unicode environment block is terminated by four zero bytes: two for the last string, two more to terminate the block.
------ end of copy paste summary ----------

I have gotten a single environment variable to work by simply entering
TEMP=$TEMPDIR$

But how do I get more than 1 environment variable? How do I null-terminate in the script/command editor?

TEMP=$TEMPDIR$$NULL$APP_HOME=$TARGETDIR$$NULL$$NULL$
did not work. Debugging the program I'm trying to install and run shows the environment variable TEMP was set to C:\\DOCUME~1\\broush\\LOCALS~1\\Temp\\$NULL$DISCUS_HOME=C:\\Program Files\\Characteristic Solutions\\DISCUS$NULL$$NULL$

BobRoush
Posts: 27
Joined: Sat Aug 26, 2006 12:26 pm

Postby BobRoush » Tue Oct 03, 2006 12:41 pm

btw, I think I'd have to be messing with this at all if the Run Program As Environment parameter were working as the underlying CreateProcess description says the lpEnvironment parameter works - If this parameter is NULL, the new process uses the environment of the calling process. If this were happening my installed, run program as exe would get the environment the installer had, which I think means TEMP and all the environment variables would be there. My debugging leads me to think some to all environment variables are not available to my run program as program.

Can you confirm that my debugging observations are what's happening? Or, if I've gone astray, point me back in the right direction.

MichaelNesmith
Posts: 3452
Joined: Thu Dec 22, 2005 7:17 pm
Contact:

Postby MichaelNesmith » Tue Oct 03, 2006 6:12 pm

Hi Bob,

The environment variables are not cleared by Run Program As, as long as you specify an empty value in this field of the command.

The string you enter in this field will be automatically null-terminated for you. But I am not sure if you can specify an entire block this way. $NULL$ was a good idea, but unfortunately that variable does not exist.

One for the wish-list maybe?
Michael Nesmith

InstallAware

Home of The Next Generation MSI Installer

Get your free copy today - http://www.installaware.com/

BobRoush
Posts: 27
Joined: Sat Aug 26, 2006 12:26 pm

Postby BobRoush » Thu Oct 05, 2006 10:16 am

Michael,
I have proof that on win xp pro sp2, if I leave the environment field blank no or at least some of the environment variables are not available to my java app wrapped inside a jsmooth built exe when invoked by the run program as command. If I put in the single possible environment variable, it is available to the jsmooth build wrapper exe and my java app. I think this or something similar is happening on win 2000, but I'm not sure.

I'll try to summarize my proof.

When I run my exe wrapped java app from the installer run program as command, I can see indications that the exe was not picking up the environment variable TEMP. The java app would startup, but throw unexpected exceptions and then hang. After the install, when I ran my exe and java app from any installed shortcuts or a command window, my app ran as normal, expected. After hours of trial and error, I was able to make my exe and java app to fail while running from a command window by clearing all the environment variables, then running app. It failed in the exact same way it was failing when started from the installer run program as command. Then I added the environment variables back in 1 to a few at a time. I determined the environment variables my app needs to run as expected from the installer run program as command are at least TEMP and SystemRoot. Further testing my reveal more. But, based upon previous posts, I cannot supply more than 1 environment variable in the run program as command.

So, I'm stuck by this problem. I need the run program as command to pass the entire environment to the invoked process when nothing is entered for the environment parameter or the ability to enter more than 1 environment variable. Actually, what I think I need (and from the IA help, what was probably intended) is the entire environment always get passed into the create process, if 1 or more environment variables are in the run program as environment parameter (say separated by something besides null), they are parsed, if the environment variable is not in the environment block, add it, else replace the previous value with the new value.

I need a fix, work around or guidance showing me where I'm wrong asap. We really want our customers to be able to run our app right at the end of the install. We think it's a nice feature/touch. I'll have to drop it for this release if you can't help me asap.

If you need me to send or attached stuff, let me know. I have a proprietary app tho, so I'll be sensitive to that.

uptime
Posts: 15
Joined: Mon Sep 18, 2006 11:33 am

Postby uptime » Fri Oct 06, 2006 1:39 pm

Contrary to what was posted earlier I do agree that the default behaviour of Run Program As is it clears almost all the environment.

However I have a solution that may work for you:
Use Run Program, this will use the current enviroment. Also, if the program has to be run in a certain location use a call dll to change the current working directory.

Code: Select all

Call DLL Function kernel32.dll->SetCurrentDirectoryA
where the only parameter is "pointer to string" and value is Directory you want (variables allowed)
return type is bool


I hope that helps, please post your results. I'de like to see what happens.

BobRoush
Posts: 27
Joined: Sat Aug 26, 2006 12:26 pm

Postby BobRoush » Fri Oct 06, 2006 1:56 pm

I went to Run Program As from Run Program because my app needs to be run from a certain location (the TARGETDIR). I'll give this a try.

uptime
Posts: 15
Joined: Mon Sep 18, 2006 11:33 am

Postby uptime » Fri Oct 06, 2006 2:31 pm

We also used Run Program As because we needed to specfiy the current working directory.

Just use the call to the dll to change the current directory (stated in above post) before you call Run Program.

BobRoush
Posts: 27
Joined: Sat Aug 26, 2006 12:26 pm

Postby BobRoush » Mon Oct 09, 2006 8:10 am

Initial testing looks like this is going to work. Thanks.

BobRoush
Posts: 27
Joined: Sat Aug 26, 2006 12:26 pm

Postby BobRoush » Mon Oct 09, 2006 4:41 pm

2nd bit of testing looks like I still have an issue. My app failed as before when the user did not have admin permissions on the target PC. I am suspecting "Call DLL Function kernel32.dll->SetCurrentDirectoryA" is failing in this situation, but have not debugged, proved this yet. My initial crack at "get result into variable SETCDRESULTS" did not work. Or, MessageBox: Set Current Directory Error, Set current directory error = $SETCDRESULTS$ does not work as I expected.

andrereg
Posts: 15
Joined: Tue Oct 24, 2006 3:43 pm
Contact:

\"Run Program As\" VS \"Run Program\"

Postby andrereg » Wed Oct 25, 2006 11:37 am

To help clear things up, "Run Program" starts with the same set of environment variables as you would have if you opened a command shell on the machine. "Run Program As" does not. This seems to make sense anyway as you might want to carefully control all available environment variables when using "Run Program As" -- so they give as close to a "clean slate" as possible. This caused me a considerable amount of confusion before i noticed the behavior difference.

Can one of the moderators confirm/unconfirm that?

I demonstated this by running the "set" command followed by a pause statement during an InstallAware install.
("Set" with no parameters just enumerates all current environment variables)

Check out the results: (Note: I'm using Install Aware v6.0)

Run Program:

ALLUSERSPROFILE=C:\\Documents and Settings\\All Users
APPDATA=C:\\Documents and Settings\\MYUSERACCOUNT\\Application Data
CommonProgramFiles=C:\\Program Files\\Common Files
COMPUTERNAME=MYMACHINE
ComSpec=C:\\WINDOWS\\system32\\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\\Documents and Settings\\MYUSERACCOUNT
INCLUDE=C:\\Program Files\\Microsoft Visual Studio .NET 2003\\SDK\\v1.1\\include\LIB=C:\\Program Files\\Microsoft Visual Studio .NET 2003\\SDK\\v1.1\\Lib\\;C:\\Program
Files\\Common Files\\DevExpress\\.NET\\;C:\\Program Files\\SQLXML 4.0\\bin\\;C:\\Program
Files\\Common Files\\DevExpress\\.NET.v2.2005\LOGONSERVER=\\\\OURDOMAINSERVER
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
Path=C:\\Program Files\\Windows Resource Kits\\Tools\\;C:\\WINDOWS\\system32;C:\\WINDOW
S;C:\\WINDOWS\\System32\\Wbem;C:\\Program Files\\ATI Technologies\\ATI Control Panel;C
:\\PROGRA~1\\COMMON~1\\SONICS~1\\;C:\\Program Files\\Common Files\\Sonic Shared;C:\\PROG
RA~1\\Borland\\Delphi6\\Bin;C:\\PROGRA~1\\Borland\\Delphi6\\Projects\\Bpl;C:\\Program Fil
es\\Borland\\Delphi6\\RemObjects SDK\\Dcu\\D6;C:\\Program Files\\Nant\\bin;C:\\Program Fi
les\\Microsoft SQL Server\\80\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\90
\\DTS\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\90\\Tools\\binn\\;C:\\Program Files
\\Microsoft SQL Server\\90\\Tools\\Binn\\VSShell\\Common7\\IDE\\;C:\\Program Files\\Micros
oft Visual Studio 8\\Common7\\IDE\\PrivateAssemblies\PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 3 Stepping 4, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=0304
ProgramFiles=C:\\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\\WINDOWS
TEMP=C:\\DOCUME~1\\MYUSERACCOUNT\\LOCALS~1\\Temp
TMP=C:\\DOCUME~1\\MYUSERACCOUNT\\LOCALS~1\\Temp
USERDNSDOMAIN=OURDOMAINDNS
USERDOMAIN=OURDOMAIN
USERNAME=MYUSERACCOUNT
USERPROFILE=C:\\Documents and Settings\\MYUSERACCOUNT
VS71COMNTOOLS=C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Common7\\Tools\VS80COMNTOOLS=C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\Tools\windir=C:\\WINDOWS
Press any key to continue . . .


Run Program As:

COMSPEC=C:\\WINDOWS\\system32\\cmd.exe
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS
PROMPT=$P$G
Press any key to continue . . .

hth,
drew

MichaelNesmith
Posts: 3452
Joined: Thu Dec 22, 2005 7:17 pm
Contact:

Postby MichaelNesmith » Wed Oct 25, 2006 4:01 pm

This was actually a bug with the Run Program As command, which has now been resolved! Thanks for helping us track this down. Just install the latest version (if you are licensed, also regenerate and reinstall your license).

The format is described in the help file - you seperate multiple variables using $NEWLINE$. The Get Environment Variable command has also been expanded to return the full existing list when a null variable is given, so you can obtain all variables and append/prepend as necessary.
Michael Nesmith

InstallAware

Home of The Next Generation MSI Installer

Get your free copy today - http://www.installaware.com/

andrereg
Posts: 15
Joined: Tue Oct 24, 2006 3:43 pm
Contact:

Postby andrereg » Thu Nov 02, 2006 10:53 am

I installed the latest version (IA 6.0.6 SP3) and verified the bug fix to Run Program As.
Thanks so much for the help! :)


Return to “Technical Support”

Who is online

Users browsing this forum: Bing [Bot] and 36 guests