22

I am trying to install a windows service.

running c:\windows\microsoft.net\Framework64\v4.0.30319\InstallUtil.exe c:\foo\MyAssembly.exe

i get a nice message that all phases (install, commit) completed successfully.

(i do not get prompted to enter service credentials)

afterwards i do not see the service in services console. nothing useful in install log.

the solution is built on a 64bit box, and i am trying to install the service on a 64bit machine. however, i do not see 64bit as an option in solution properties. i did manually edit all the csproj files to select "x64" for [platform] nodes..

i can run the service out of visual studio no problem.

installer.cs

[RunInstaller(true)]
public partial class Installer : System.Configuration.Install.Installer
{
    public Installer() {
        InitializeComponent();
    }
}

this is the default installer provided by visual studio.

Sonic Soul
  • 23,855
  • 37
  • 130
  • 196
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". Also, if it's a question of installation, then this likely has nothing to do with WCF, so I removed that tag. – John Saunders Sep 11 '12 at 03:50
  • Sorry! Wrong choice of Words. The installation Script!! – madhairsilence Sep 11 '12 at 03:53
  • madhairsilence.. is installer.cs what you were asking for ? – Sonic Soul Sep 11 '12 at 04:09
  • 2
    Also worth noting - if you're running via cmd prompt - make sure you are running as administrator. I just ran into this issue. – Tikeb Mar 17 '15 at 10:20

2 Answers2

30

You need to add some Installer objects to the Installers collection. The example here is what you want for installing a windows service. Something like

[RunInstaller(true)]
public class Installer : System.Configuration.Install.Installer
{
    private ServiceInstaller serviceInstaller;
    private ServiceProcessInstaller processInstaller;

    public Installer()
    {
        // Instantiate installers for process and services.
        processInstaller = new ServiceProcessInstaller();
        serviceInstaller = new ServiceInstaller();

        // The services run under the system account.
        processInstaller.Account = ServiceAccount.LocalSystem;

        // The services are started manually.
        serviceInstaller.StartType = ServiceStartMode.Manual;

        // ServiceName must equal those on ServiceBase derived classes.
        serviceInstaller.ServiceName = "Hello-World Service 1";

        // Add installers to collection. Order is not important.
        Installers.Add(serviceInstaller);
        Installers.Add(processInstaller);
    }
}
Mike Zboray
  • 39,828
  • 3
  • 90
  • 122
0

The following SO Question has similar scenarios and answers that may also be relevant to someone coming here from a Google search link.

Install Windows Service created in Visual Studio

Community
  • 1
  • 1
Sql Surfer
  • 1,344
  • 1
  • 10
  • 25