Israel
Posts: 14
Joined: Mon Dec 17, 2007 2:53 pm

Retrieving installer command line parameters

Hi,

How can I retrieve the command line parameters while running the installation?

In particular, I would like to pass the full path of the log file as a parameter to a custom action.

Thanks in advance,

Israel Sadeh
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

I'm afraid that this is not supported directly by Windows Installer.

However, you can set properties using the command line and use them as parameters for your custom action. For example if you run a MSI package with the command:

Code: Select all

msiexec /i package.msi PATH_LOG="C:\Test\package.log"
you can use for your custom action the property PATH_LOG.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Israel
Posts: 14
Joined: Mon Dec 17, 2007 2:53 pm

Hi Cosmin,

I didn't quite understand how can I retrieve the path of the log file using properties.
When I run an installation using the command

msiexec /lv full_log_file_folder_and_name

How can I later on pass the value of full_log_file_folder_and_name to a custom action.

Are you suggesting that I can define the property PATH_LOG instead of using the /l switch? What level of logging will it use?

Is there a way to define the logfile name and logging level from within the MSI file using some predefined properties?


Thanks,


Israel
[/code]
Lon
Posts: 10
Joined: Fri Jun 15, 2007 9:08 pm
Location: Virginia USA

Retrieving installer command line parameters

Hi

My installation has many command line parameters and I needed to do a lot of processing on those parameters both before and after installation of the files.

My pre-processing included verification of the command line parms such that if it failed, then the actual install would stop before a single file was extracted. The post install included editing an application config file to include some of the command line parms. While you cannot get the full command line as a single property, you can pass individual properties.

In my case, the magic happens in the Advanced Installer >> Custom Actions >> Install and Commit phases. I created a simple DLL using MS Visual Studio that exposed a simple validation routine and an editing routine for the install and commit phases respectively. Then you pass the properties (case matters) on the command line like DEBUG="true" or PORT=1024 and also put them into the Advanced Installer's >> Custom Action >> action data field in brackets like debug=[DEBUG] port=[PORT].

In the DLL (you can also java script or visual basic script) you get the installer properties using:

ok = GetMsiProperty("CustomActionData", sMyCustomActionValue);

My DLL's are quite extensive doing a lot of verification, pulling certificates across the network and editing files which compliment advanced installer very nicely. The trick (most time lost) was figuring out how to get the command line parms into advanced installer and then into my code. It turned out to be quite easy. It was also very easy to waste a lot of time. Hints:

1. Property case (scope) matters

2. Properties are specified in brackets like [DEBUG] will produce the value "true".

3. Some properties require a special vertical bar following them (I don’t remember why).

4. There was no need to define the properties in the Advanced Installer >> Install Parameters >> Properties panel.

5. You CAN access properties during install using Custom Actions >> Install >> Synchronous >> Deferred with no impersonation for Vista. However, the actual files are NOT available during this phase because the install hasn’t started yet.

6. You can NOT access properties during the commit phase, but you CAN access the files because they have already been extracted.

7. To keep properties values between install and commit phase, your external program must persiste them somewhere (like the registry or some temp file, but not in memory since the DLL access from each phase is completely independent.

Hope this helps
Lon
Israel
Posts: 14
Joined: Mon Dec 17, 2007 2:53 pm

Hi Lon,

Thanks for your advice.

Is there also an API for for extracting the name of log file that was specified in the command line?

Israel
Lon
Posts: 10
Joined: Fri Jun 15, 2007 9:08 pm
Location: Virginia USA

Retrieving installer command line parameters

I am not aware of an API to get the log file name, but I would not doubt you get it from the handle provided by the custom action entry point.

Here's a scaled down example of a DLL entry point (using visual c++). The entry point is exposed to Advanced Installer >> Customer Action >> Install (phase) >> Function Name. When the install phase executes, it calls my DLL with a handle from MSI which can then be used to write records to the log file.

extern "C" BOOL PASCAL EXPORT ExternalEntryPoint(MSIHANDLE hMsiInstaller)
{
CString sString = "Hello world" ;

PMSIHANDLE hRecord = MsiCreateRecord(2);
MsiRecordSetString(hRecord, 1, sString);
MsiProcessMessage(hMsiInstaller, INSTALLMESSAGE_INFO, hRecord);
}

Again, I wouldn’t doubt there is a way to get the actual filename.

Alternatively, you can pass a property LOG="MyLogFile.log" on the command line (as suggested earlier) and write to that file using typical file functions. This works (I did this too for a while) but then your log messages are not integrated with the MSI log messages which provides limited value.
Israel
Posts: 14
Joined: Mon Dec 17, 2007 2:53 pm

Thanks again,

Israel
invalidptr
Posts: 79
Joined: Thu Nov 18, 2010 7:10 pm

Re: Retrieving installer command line parameters

3. Some properties require a special vertical bar following them (I don’t remember why).
AI documentation refers to the vertical bar ("|") as the pipe character. It appears to have different uses in different contexts. My context is in Extract Location.
[AppDataFolder][|Manufacturer]\[|ProductName]\install
What does it mean in that context?
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Retrieving installer command line parameters

Hello,

In the case of the Extract Location text field, the pipe character is part of the property referencing syntax. This text field is PseudoFormatted which means the property references are replaced with the value of the respective properties at build time.

Regards,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
invalidptr
Posts: 79
Joined: Thu Nov 18, 2010 7:10 pm

Re: Retrieving installer command line parameters

Thanks Mihai, may I suggest adding the phrase "pipe character" to the PseudoFormatted documentation page. Help's Search won't allow you to search for the "|" character so I wasn't able to find the page you referenced on my own. BTW, I call this character a vertical bar.
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Retrieving installer command line parameters

Hello,

Thank you for your suggestion, I have forwarded your request to our technical writing team and the modification will be available in a future release.

Regards,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”