views:

1727

answers:

3

Hi,

I'm trying to use an installer for a Windows service, and would like to avoid using InstallUtil.exe. The installer appears to work correctly (the executable and dlls are in the correct directory), but the service doesn't appear under Computer Management.

Here's what I've done so far:

The service class name is the default - Service1.

In the Project installer, the ServiceName of the service installer matches the class name - Service1.

Under the Custom Actions, the primary output of the service was added to Install, Commit, Rollback, and Uninstall.

I'm using http://support.microsoft.com/kb/816169 as a reference.

Any ideas?

+2  A: 

Make sure you've created a ServiceInstaller and ServiceProcessInstaller class in your service project. (Check this link for more info).

Close computer management and the Services window, run your installer again, and reopen the Services window.

If that doesn't work, restart your computer. You might have some files locked.

It goes without saying that you probably need administrative privileges on the machine for this to work properly.

Robert Harvey
The example code in the link posted got me on the right track, thanks a bunch.
David Hodgson
A: 

I think I've figured it out. It might be a bug with the Designer code, or perhaps I missed a step.

I think in the designer code, in the InitializeComponent() method, it's supposed to add:

this.Installers.AddRange(new System.Configuration.Install.Installer[] {this.serviceProcessInstaller1, this.serviceInstaller1});

It wasn't there, so I added this in the ProjectInstaller constructor:

Installers.Add(serviceInstaller1);
Installers.Add(serviceProcessInstaller1);

Now on installation, it's listed as a service in Computer Management.

David Hodgson
+4  A: 

Does your service project have an Installer class? You should have one that looks something like this:

[RunInstaller(true)]
public partial class Service1Installer : Installer
{
    public Service1Installer()
    {
        InitializeComponent();
        ServiceProcessInstaller process = new ServiceProcessInstaller();
        process.Account = ServiceAccount.LocalSystem;

        ServiceInstaller serviceAdmin = new ServiceInstaller();
        serviceAdmin.StartType = ServiceStartMode.Manual;
        serviceAdmin.ServiceName = "Service1";
        serviceAdmin.DisplayName = "Service1";
        serviceAdmin.Description = "Service1";

        Installers.Add(serviceAdmin);
    }
}
SpaceghostAli
That's what I was missing. I thought the Installers.Add() part would be included in the auto-generated Designer code, but it wasn't. Maybe they changed it?
David Hodgson
Yes I saw you figured it out just as I was posting
SpaceghostAli