1

I'm trying to create multiple services using one EXE file.

I've added a installer class:

[RunInstaller(true)]
public partial class POCInstall : System.Configuration.Install.Installer
{
    private ServiceProcessInstaller m_ServiceProcess;
    private ServiceInstaller m_ServiceInstaller;
    public POCInstall()
    {
        InitializeComponent();

        m_ServiceProcess = new ServiceProcessInstaller();
        m_ServiceProcess.Account = ServiceAccount.NetworkService;
        m_ServiceProcess.Username = null;
        m_ServiceProcess.Password = null;

        m_ServiceInstaller = new ServiceInstaller();
        m_ServiceInstaller.BeforeInstall += new InstallEventHandler(onBeforeInstall);
        m_ServiceInstaller.BeforeUninstall += new InstallEventHandler(onBeforeUninstall);
        m_ServiceInstaller.BeforeRollback += new InstallEventHandler(onBeforRollback);
        m_ServiceInstaller.ServiceName = "POCService";
        this.Installers.Add(m_ServiceProcess);
        this.Installers.Add(m_ServiceInstaller);
    }

    private void onBeforRollback(object sender, InstallEventArgs e)
    {
        string serviceName = ConfigurationManager.AppSettings["ServiceName"];
        string serviceDsiaply = ConfigurationManager.AppSettings["ServiceDsiaply"];
        m_ServiceInstaller.ServiceName = serviceName;
        m_ServiceInstaller.DisplayName = serviceDsiaply;
    }

    private void onBeforeUninstall(object sender, InstallEventArgs e)
    {
        string serviceName = ConfigurationManager.AppSettings["ServiceName"];
        string serviceDsiaply = ConfigurationManager.AppSettings["ServiceDsiaply"];
        m_ServiceInstaller.ServiceName = serviceName;
        m_ServiceInstaller.DisplayName = serviceDsiaply;
    }

    private void onBeforeInstall(object sender, InstallEventArgs e)
    {
        string serviceName = ConfigurationManager.AppSettings["ServiceName"];
        string serviceDsiaply = ConfigurationManager.AppSettings["ServiceDsiaply"];
        m_ServiceInstaller.ServiceName = serviceName;
        m_ServiceInstaller.DisplayName = serviceDsiaply;
    }

}

As you can see, I get the service name and parameter from the app config file:

 <add key="ServiceName" value="POCService1"/>
 <add key="ServiceDsiaply" value="POC Service 1"/>

The service class is empty and only have empty onStart and OnStop methods.

public partial class POCService : ServiceBase
{
    public POCService()
    {
        this.ServiceName = "POCService";
        InitializeComponent();
    }

    protected override void OnStart(string[] args)
    {
    }

    protected override void OnStop()
    {
    }
}

When I do the install using command line, %SystemRoot%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe ServicePOC.exe

I get the error:

An exception occurred during the Rollback phase of the System.ServiceProcess.ServiceInstaller installer. System.ArgumentException: The savedState dictionary does not contain the expected values and might have been corrupted.

1

1 Answer 1

1

Implement an empty public override void Commit(IDictionary savedState) method.

2
  • This initially seemed to work for me but then on trying to uninstall the next next version (with the empty method in) I had the same problem again.
    – d219
    Jun 3, 2019 at 10:31
  • For info editing the installState file seems to have worked for me - see stackoverflow.com/questions/6618634/…
    – d219
    Jun 3, 2019 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.