views:

2172

answers:

4

I would like to be able to pass parameters in the installation of the service. I have modified the C# code of the class that inherit from Installer... My problem is the InstallUtil.exe doesn't work with parameters (well not as I know).

Any suggestion?

A: 

Try NSIS. It's a scripting language built for installations, allows you to do all manner of complex things. Personally, I'd use it for any installation that goes beyond "Next, Next, Next". Very slick, and not all that hard to learn.

Faqa
A: 

Build and installer with either Visual Studio or something like Wix. In Visual Studio, you can do a Custom Action and pass in parameters in the CustomActionData field.

JP Alioto
+3  A: 

We have the same scenario and it works. You've to pass the parameters as follows

InstallUtil.exe /Param1="Value" /Param2="Value" "Path to your exe"

Then you've to override Install method on your installer

public override void Install(System.Collections.IDictionary stateSaver)
{
     var lParam1 =   GetParam("Param1");
}

private string GetParam(string pKey)
{
        try
        {
            if (this.Context != null)
            {
                if (this.Context.Parameters != null)
                {
                    string lParamValue = this.Context.Parameters[pKey];
                    if (lParamValue != null)
                        return lParamValue;
                }
            }
        }
        catch (Exception)
        {
        }
        return string.Empty;
    }
Vasu Balakrishnan
Just for future reference : If you pass a service name by parameter (dynamic service creation), you need to get the parameter in the OnBeforeInstall. Thank you for this answer.
Daok
+1  A: 

Actually it can be done with InstallUtil.exe, the .NET installer utility that comes with the .NET Framework.

Take a look at this CodeProject article.

mjmarsh
The page is very poor, but the source code show me something interesting, +1.
Daok