Page 1 of 1

Runtime variable assignment.

Posted: Fri Feb 13, 2009 10:24 am
by bokkie
I have a variable in my MSIcode called TEST123 which I've initialised to 1234567890.

It's defined as Set Variable TEST123 to 123 and it's inside the [DEFINE REGION: Define Setup Globals] region.

If I display the value during installation it displays the default value.

Now, I've tried running the msi using these two commands:

test.msi TEST123=69100

msiexec /i test.msi CMDLINE='TEST123=69100'

In both cases, the value of TEST123 is displayed as 1234567890. I'm happy to accept that I'm doing something wrong or misunderstanding the connection between MSIcode variables and changing their values on the command line but can someone tell me what I'm doing wrong?

Am I right in thinking that I can provide a different value that overrides the default for the variable?

Posted: Fri Feb 13, 2009 1:06 pm
by MichaelNesmith
Good observations. Try running setup with the silent command line parameter /s. Then it will work. Otherwise, your script will be overriding the command line values the moment it hits Set Variable. Such override is prevented in silent setups.

Also another observation. You can never use msiexec to run an InstallAware setup. The InstallAware bootstrapper is always required for a multitude of reasons (read the MSIcode Scripting whitepaper on why this is a good thing).

The better news is, unlike the InstallShield bootstrapper, the InstallAware bootstrapper never installs anything, does not have any runtime dependencies on COM or any other framework, and runs all the way down-level including Windows 95 Gold (first ever version) released all the way back in August 1995. 14 year platform support from InstallAware :)

Posted: Fri Feb 13, 2009 3:54 pm
by bokkie
MichaelNesmith wrote:Good observations. Try running setup with the silent command line parameter /s. Then it will work. Otherwise, your script will be overriding the command line values the moment it hits Set Variable. Such override is prevented in silent setups....
Michael, why would the /s work and not without it? Would there not be a case to see how command line variables affect the UI for example, which /s would presumably suppress?

Posted: Fri Feb 13, 2009 6:51 pm
by MichaelNesmith
Basically, Set Variable always overrides variables set from the command line, unless setup is running in silent mode, and there is no expectation of user input possibly changing command line parameters.

Otherwise end-users cannot override command line parameters from the GUI while setup is running and this is confusing.

If you have any suggestions on how to improve this mechanism, we're all ears :)

Note that you can always access whatever is in the command line using If Contains and the CMDLINE pre-defined variable, so you can define your custom command line parameters any way you like and access them from MSIcode at all times.

Posted: Sat Feb 14, 2009 5:46 am
by bokkie
Michael,

I have this MSIcode:

Write into Text File C:\\Temp\\Test123value.txt from Value The command line is: $CMDLINE$ (at end of file)
Set Variable TEST123 to 123
if Variable $CMDLINE$ Contains (Ignore Case) TEST123
Set Variable TEST123 to $TEST123$
end
Write into Text File C:\\Temp\\Test123value.txt from Value The value of TEST123 is: $TEST123$ (at end of file)


If I use this command line:

test.exe /s TEST123=69100 ANOTHER='Other value'

The value of TEST123 is written to the output file with the value 69100 so that's correct.

If I use this command line:

test.exe /s CMDLINE="TEST123=69100 ANOTHER='Other value'"

The value written to the output file is still the default value of 123. That is, wrapping the variables and values in a quoted CMDLINE does not override the default in my MSIcode. I've probably misunderstood the use of the CMDLINE variable. It's just as probable that my MSIcode above handles non-CMDLINE declarations but might need a different MSIcode construct to get the values from CMDLINE. I'm happy to accept that I'm not handling CMDLINE correctly in my code.

Either way, not wrapping my variables in CMDLINE works ok and the override does occur.

I also noticed that when using non-CMDLINE only the variables and data values are written to my output file. If I use the quoted CMDLINE the output file also contains the /s silent option. I've no problem with that and it's just an observation.