Dec 7 2007

Windows Installer Argument Passing

Category: Windows SetupBil@l @ 20:06

In a Windows Installer setup project I was developing, I had the need to run a script on the Install action of the Windows Installer. There could be several ways of doing so either using:

  1. vbs
  2. Windows Installer Class
  3. exe application

I decided to go for a Console application. However, I needed to perform some logic inside the console application based on parameters from the Windows Installer. So how can I pass parameters from the Windows Installer to the custom action handlers?

In the figure below, you can see that I am viewing the Windows Installer files in a Custom Action View:

 

I have added an EXE application to run at the Install action of the Windows Installer. If you select the Properties window of the EXE you notice the Arguments property. Here you can pass as many arguments as you want by surrounding the argument with a double quotes.

In the above example, I am passing the

  1. TARGETDIR: This property gets the path of the folder where the Windows Installer shall use to install the accompanying files on the user's machine.
  2. SOURCEDIR: This property gets the path where the MSI is being executed and running on the user's machine.

You could pass any property you want. Here is a link to a very wonderful reference for all the properties that you could pass in a Windows Instalelr: Windows Installer Property Reference

Now, inside the AddToExplorer, you could access the above two arguments as follows:

static void Main(string[] args)
{
    if ((string.IsNullOrEmpty(args[0])) || (string.IsNullOrEmpty(args[1])))
        throw new ArgumentException("Input parameters are invalid");

    string targetDir = args[0];
    string sourceDir = args[1];

 

Hope this post is useful for you!

Regards

Tags:

Comments are closed