61

I've created a windows service in C#, using Visual Studio 2008 I pretty much followed this: http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx

I created a setup project, as instructed to in the article, and ran it... it installs my service to C:\Program Files\Product etc.... however, it does not then appear in the services list..

What am I missing?

3
  • Hard to guess without further information. If you did everything as described in the article and installed the service it should be available.
    – Foxfire
    Commented Oct 13, 2009 at 14:00
  • Did you try refreshing the services console? The list in the console does not update automatically. If you already had the console open when you installed your service, try refreshing it (or re-starting it).
    – Matt Davis
    Commented Oct 13, 2009 at 14:21
  • Too late but worth to mention: Add custom action to setup and make sure Installer class is public Commented Jul 6, 2018 at 5:40

9 Answers 9

118

The most important part of the article you linked, is here

To add a custom action to the setup project

1.In Solution Explorer, right-click the setup project, point to View, then choose Custom Actions. The Custom Actions editor appears.

2.In the Custom Actions editor, right-click the Custom Actions node and choose Add Custom Action. The Select Item in Project dialog box appears.

3.Double-click the application folder in the list box to open it, select primary output from MyNewService (Active), and click OK. The primary output is added to all four nodes of the custom actions � Install, Commit, Rollback, and Uninstall.

4.Build the setup project.

If you skip these steps, your setup project will build and copy your files to the correct directory; however, they will not register your binary as a service without these steps.


I should also note that this works for older versions of Visual Studio that had/have the built-in Setup/Deployment project template. The newer versions of Visual Studio have different setup/deployment projects (some requiring third party software.)

I'd recommend looking into WiX Toolset and check here for WiX Installation of Windows Services.

3
  • 2
    Is there any way to start the service as part of the install as well? I know you can configure StartType to Automatic, but that only starts the service after a restart. Commented Feb 24, 2010 at 1:44
  • 1
    Thanks so much @Nate. As I was going through your instructions it came back to me that this is what I had to do last time. Commented Nov 1, 2011 at 10:11
  • 1
    Spot on ! Thanks , it helped me
    – hakuna
    Commented Oct 17, 2017 at 18:14
8

I got owned in the face by this one, so I'm putting it here just in case anyone else runs into it.

If you followed the instructions in the guides but are still having issues installing, ensure your Installer class is public. Internal won't work.

1
  • Oh man, thanks. I think this is just crazy! I got cocky and thought "meh, its just an installer - why bother making the class wrapper public?" and deleted it without even thinking - boom, issue came up.
    – Alexandru
    Commented Mar 9, 2014 at 6:25
6

I had this same issue and then I realized that I never set the parent for the ServiceInstaller.

Double-click on your project installer. The designer should show a Service Installer and Process Installer. When you click on either and view the properties you should note the Parent attribute which must both be set to the class name of the Project Installer.

Or, if you do it in code, make sure you set:

serviceInstaller.Parent = this;

and

serviceProcessInstaller.Parent = this;
0
3

When installing services, I would highly recommend using NSSM, which worked well for me for all my WinService needs. It can install any executable (even if .bat, .cmd) as a service, and guarantees your service is always up and running.

To use this tool:

  1. Download from here

  2. And follow the instructions here

Then check the services list, it should be there, up, and running.

0

Follow these instructions, they worked for me. For the setup specifically, that part is near the bottom of the article.

MSDN: Walkthrough: Creating a Windows Service

2
  • 3
    this link is outdated
    – andrepaulo
    Commented Jan 7, 2019 at 15:42
  • It's a problem with all documentation links from microsoft. They regularly delete their information, which then breaks links to their site. Kinda sad really.
    – Ro Yo Mi
    Commented May 18, 2022 at 13:20
0

In Visual Studio 2013 I ran into the same problem using InstallShield template for service application. But it works like charm when using Setup Project template https://visualstudiogallery.msdn.microsoft.com/9abe329c-9bba-44a1-be59-0fbf6151054d

so download Setup Project template close your Studio, run this installation and start your Studio, this will work.

Dunn.

0

Here is a good tutorial from tgeek001 from CodeProject.com that helped me. It includes several things I didn't see in the posts above: 1. Event handler code to stop the service before uninstalling it 2. Specific conditions and properties in the Custom Actions code to set in order to prevent failures (these fixed the Error 1001 that I experienced while following the instructions in the accepted answer above) 3. Win Service property "Remove Previous Version" dropdown set to true

http://www.codeproject.com/Tips/575177/Window-Service-Deployment-using-VS

The following is from the tutorial for Custom Actions Settings (case matters):

  • Install, set the Condition property to the following: "NOT (Installed or PREVIOUSVERSIONSINSTALLED)"
  • Uninstall, set the Condition property to: "NOT UPGRADINGPRODUCTCODE"
  • Commit: set "Custom Action Data" field to: /OldProductCode="[PREVIOUSVERSIONSINSTALLED]"

Lastly, in the WinService project, make sure to set the dropdown "Remove Previous Versions" to true.

cheers

0

I discovered that your installer class much be in the same project as the Service. The installer cannot exist in a library project referenced by the Service.

0

remember to check the name you've given your service before you search. (right click-> properties->check the service name

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