Friday, March 4, 2011

Set MSI Property values through command line

Often we come across situations like how to update MSI properties during setup installation, which we may have hard coded at design time. It takes a lot of time to search in the help sections, or on Google, if the solution is needed in a go. Here is a way how to do that, which I had implemented a lot of times. Any better way is most welcomed.


Like your compiled .msi file, setup.exe can accept a number of command-line parameters.


With these parameters, we can specify data such as which language installer should run in, and whether to run setup.exe silently.


NOTE:
Command-line options that require a parameter must be specified with no space between the option and its parameter. For example, Setup.exe /v"ALLUSERS=2" is valid, while Setup.exe /v "ALLUSERS=2" is not. Quotation marks around an option's parameter are required only if the parameter contains spaces. If a path within a parameter contains spaces, you may need to use quotation marks within quotation marks, as in the following example: Setup.exe /v"INSTALLDIR=\"c:\My Files\"".



Ex:
setup.exe /v"MSIPROPERTY=Value"


where, MSIPROPERTY is any Msi Property setup inside the installer code.


More help on command line options

Uninstalling previous version during upgrade

 In my last project, I face a scenario where we need to uninstall previous version installed on the machine, before installing the new version. Although that requirement was later on pulled back, but since then I came to know how we can uninstall a product from within our code.


UninstallApplication:
UninstallApplication function launches the uninstallation that is specified by szUninstallKey.



Syntax:
UninstallApplication(szUninstallKey,szAdditionalCmdLine,nOptions)


Parameters: 
szUninstallKey --
Specifies the name of a subkey under the target registry's [root]\Software\Microsoft\Windows\CurrentVersion\Uninstall key; the function first
checks for the subkey under the root key HKEY_CURRENT_USER, and if it does not
find the subkey there, it checks under HKEY_LOCAL_MACHINE. For setups created
with InstallShield Professional 5.53 or earlier, this is typically the name of the application; for setups created with InstallShield Professional 6.0 or later, this is the application's product GUID including the surrounding braces ({}). Do not enter the product GUID of the current setup.


szAdditionalCmdLine:
Specifies any additional command line arguments that you want to pass to the uninstallation. You do not need to specify command line arguments that are already specified in szUninstallKey's UninstallString value's data.


nOptions:
Specifies additional options. You can specify any option that is supported by LaunchApplication


Example:

RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
sExeRegistryPath="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\InstallShield_{D0BAAF19-362E-48C7-8640-43B66DD381E5}";
if (RegDBKeyExist(sExeRegistryPath) = 1) then
szUninstallKey = "";
szUninstallKey = "InstallShield_{D0BAAF19-362E-48C7-8640-43B66DD381E5}";
//Specified for silent uninstallation
szAdditionalCmdLine="/uninst";
UninstallApplication ( szUninstallKey, szAdditionalCmdLine, LAAW_OPTION_WAIT||LAAW_OPTION_MINIMIZED);


abort;
endif;