7

I have written a Windows Service.

I now want to package it up in an installer.

I have used the VS2013 x86 Native Tools Command Prompt and then used the commands:

To install it:

installutil httpapiservice.exe

To uninstall it:

installutil httpapiservice.exe /u

This works perfectly. I can see the new service in "Services" and stop and start it no problem.

I then proceeded to right click on the project and select "Publish" and it produced a setup.exe

But, when I run the setup.exe I can see it "downloading and extracting" the files. It looks like it's installing but nothing appears in "Services"

Can anyone tell me if I am doing it correctly please?

Thanks

Trevor Daniel
  • 3,785
  • 12
  • 53
  • 89
  • 2
    I realize that you've already written your Windows service, but I suggest you learn about and use [Topshelf](http://topshelf-project.com) to manage your Windows service installs and uninstalls, which would require some refactoring of your code. – Sameer Singh Apr 09 '14 at 08:45
  • Check here : https://stackoverflow.com/questions/1560407/windows-service-not-appearing-in-services-list-after-install – hakuna Oct 17 '17 at 18:14
  • I recommend watching this video. https://www.youtube.com/watch?v=cp2aFNtcZfk Tried and verified – Ahmed IG Nov 30 '15 at 00:58

4 Answers4

16

You need to add a setup project to your solution to build an installer executable.

Unfortunately Microsoft removed their setup project template from Visual Studio 2012 onwards, which would have done the job.

This means you are stuck with one of the alternatives, which are either less functional, harder to set up, or expensive.

NOTE - scroll down to EDIT 3 for my recommended solution. The rest of this post is just to highlight alternatives.

If you fancy the free route you can add on InstallShield Limited Edition to Visual studio, and use it to create a setup project for your solution. It will work for windows service setup projects in the latest version, but is generally considered pretty rubbish and limited. Here's the instructions for this: link

WiX is a free open source alternative, which is far more functional, but tricky to set up.

EDIT -

Here's an article describing how to use WiX to create a setup project: http://www.schiffhauer.com/wix-template-for-installing-a-windows-service/

EDIT 2 -

As of today (22/04/2014) Microsoft have reinstated the setup project in Visual Studio 2013 as an Visual studio extension - see this post

I've not tried it myself, but it's presumably the same as the VS2010 setup project, which wasn't too hard to learn (and there's plenty of help available on the internet) I'd definately recommend you try this for creating your setup program!

EDIT 3 (Apr 2016) -
I'd highly recommend you use the Visual Studio Installer Projects Extension (as mentioned in the above edit) for creating simple installers for your windows services (and other programs too). The installers it creates are simple, but professional looking enough for simple or small projects.

The extension for Visual Studio 2013 is here
The extension for Visual Studio 2015 is here
The extension for Visual Studio 2017 is here

An article describing how to create a setup project for a windows service using the old VS2010 Setup project is here. Although this is an old article it can be applied directly to the new Installer Project extensions linked above. (Thanks EbbnFlow for the link)

James S
  • 3,558
  • 16
  • 25
  • wow. that sounds harder than writing the code in the first place. lol :) – Trevor Daniel Apr 08 '14 at 21:19
  • 1
    InstallShield LE isn't that hard to use, just limited. It might be enough for you though, assuming you don't need to customise the install too much, or pick the service user during the setup process. Give it a try! The alternative: WiX has a pretty steep learning curve, but you might be able to find a pre-written template for windows service setup projects to make your life easier – James S Apr 09 '14 at 08:11
  • Upvote for mentioning the Visual Studio 2013 extension. – bvj Jan 12 '15 at 21:49
  • The setup project in 2013 doesn't support services. – Christopher Edwards Feb 19 '15 at 20:22
  • @JamesS Can you point to a resource that explains why Microsoft made the awful decision to remove it in the first place even if they came out with an extension later? – oscilatingcretin May 29 '15 at 12:44
  • 3
    @oscilatingcretin Don't have a link to hand, but I suspect its because they (a) couldn't be bothered maintaining it, and more likely (b) took a big payoff from Flexera (Installshield developers) Hopefully they've now seen the light, and realized that they shouldn't be satisfying a commercial partner at the cost of their developer community – James S May 29 '15 at 13:01
  • @Christopher Edwards It sure does support services. Here's how I got mine to work using the 2013 setup project https://support.microsoft.com/en-us/kb/816169. – EbbnFlow Sep 03 '15 at 18:46
  • @EbbnFlow You realize we're talking about VS 2013 and the article you linked only goes through 2008 (although I suspect that 2010 isn't much different). Edit2 makes the most sense since it is a logical continuation of the functionality that was temporarily discontinued with VS 2012. – CSS Sep 11 '15 at 15:59
  • 1
    @CSS I do. It does work though. I have verified that it works with the VS 2013 setup project myself. – EbbnFlow Sep 21 '15 at 15:48
2

I ended up zipping up the software and including installutil.exe and simply gave the customer instructions have to install and uninstall.

Seems to have worked perfectly.

HTH

Trevor Daniel
  • 3,785
  • 12
  • 53
  • 89
  • I guess you could take it one step further and write a little winforms app with [Install] and [Uninstall] buttons that execute the right command strings. – Steven Liekens Apr 10 '14 at 06:50
  • This works for 2013 setup projects. https://support.microsoft.com/en-us/kb/816169 – EbbnFlow Sep 03 '15 at 18:47
1

It seems you want to use ClickOnce (publish) to install a service. This isn't possible without a hassle but you can try to do it as described in this answer.

Community
  • 1
  • 1
tobsen
  • 5,328
  • 3
  • 34
  • 51
1

These official Microsoft extensions provide support for Visual Studio Installer Projects in Visual Studio 2013 https://visualstudiogallery.msdn.microsoft.com/9abe329c-9bba-44a1-be59-0fbf6151054d and Visual Studio 2015 https://visualstudiogallery.msdn.microsoft.com/f1cc3f3e-c300-40a7-8797-c509fb8933b9

With these extension and the video in the previous post I was able to make a setup project for a windows service in Visual Studio Community 2015.

Don't forget to add the custom actions for install and uninstall (as described in the video) and also don't forget to add the installer class to your service project to get your service correctly installed under system --> services.

I've added the serviceProcessInstaller and the serviceInstaller-component by code and configured it like this:

public XxxServiceInstaller()
{
    InitializeComponent();

    ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
    ServiceInstaller serviceInstaller = new ServiceInstaller();

    // Service Account Information
    serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
    serviceProcessInstaller.Username = null;
    serviceProcessInstaller.Password = null;

    // Service Information
    serviceInstaller.ServiceName = "your service name";
    serviceInstaller.DisplayName = "your service display name";
    serviceInstaller.StartType = ServiceStartMode.Manual; // or automatic

    this.Installers.Add(serviceProcessInstaller);
    this.Installers.Add(serviceInstaller);

    this.AfterInstall += new InstallEventHandler(ProdSSSyncServiceInstaller_AfterInstall);
}

void XxxServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
{
    ServiceController sc = new ServiceController("your service name");
    // start immediately
    sc.Start();
}
guppy81
  • 91
  • 1
  • 4