C# - windows service installer not registering service

David Hodgson picture David Hodgson · Jul 27, 2009 · Viewed 14.7k times · Source

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?

Answer

HasaniH picture HasaniH · Jul 27, 2009

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);
    }
}