views:

147

answers:

1

hi

When I start to installing using installutil it gives me following error, I have set ServiceInstaller and ServiceInstallerProcess

System.InvalidOperationException: Installation failed due to the absence of a ServiceProcessInstaller. The ServiceProcessInstaller must either be the containing installer, or it must be present in the Installers collection on the same installer as the ServiceInstaller.

Waiting for your valuable thoughts.

Thanking You

+1  A: 

Usually, this means you failed to attribute your installer with RunInstaller(true). Here's an example of one I have handy that works:

namespace OnpointConnect.WindowsService
{
    [RunInstaller(true)]
    public partial class OnpointConnectServiceInstaller : Installer
    {
        private ServiceProcessInstaller processInstaller;
        private ServiceInstaller serviceInstaller;

        public OnpointConnectServiceInstaller()
        {
            InitializeComponent();
        }

        public override string HelpText
        {
            get
            {
                return
                    "/name=[service name]\nThe name to give the OnpointConnect Service.  " +
                    "The default is OnpointConnect.  Note that each instance of the service should be installed from a unique directory with its own config file and database.";
            }
        }

        public override void Install(IDictionary stateSaver)
        {
            Initialize();
            base.Install(stateSaver);
        }

        public override void Uninstall(IDictionary stateSaver)
        {
            Initialize();
            base.Uninstall(stateSaver);
        }

        private void Initialize()
        {
            processInstaller = new ServiceProcessInstaller();
            serviceInstaller = new ServiceInstaller();
            processInstaller.Account = ServiceAccount.LocalSystem;
            serviceInstaller.StartType = ServiceStartMode.Manual;

            string serviceName = "OnpointConnect";
            if (Context.Parameters["name"] != null)
            {
                serviceName = Context.Parameters["name"];
            }
            Context.LogMessage("The service name = " + serviceName);

            serviceInstaller.ServiceName = serviceName;

            try
            {
                //stash the service name in a file for later use in the service
                var writer = new StreamWriter("ServiceName.dat");
                try
                {
                    writer.WriteLine(serviceName);
                }
                finally
                {
                    writer.Close();
                }

                Installers.Add(serviceInstaller);
                Installers.Add(processInstaller);
            }
            catch (Exception err)
            {
                Context.LogMessage("An error occured while creating configuration information for the service.  The error is "
                                   + err.Message);
            }
        }
    }
}
Tom Cabanski