views:

216

answers:

4

I just created a simple .NET Windows service. My users are supposed to download it from my site and install it on their computers. So, from various forum posts (including this site) I know that in order to do this I need an installer. Or I can just give them service files and instruct how to install it. I begun with creating a setup project and was able to compile my own .msi installer. But one user complained that he cannot uninstall it now. I researched it and found that .msi format has some issues, mostly related to the way it counts references in GAC. It was very easy to help him to fix his computer, though. From my conversations with users I know that it would be close to impossible to train them to use sc.exe or installutil.exe. I also found a service at http://installer.codeeffects.com that can build an installer for my service without any code but I'm not sure if my installer should be msi or exe. So, clearly I'm in a total confusion here :) Please help guys, any general or detailed advise will be highly appreciated.

A: 

My suggestion would be the MSI to install the files in the required location, including batch files that execute the installutil.exe. Then Post Installation steps that execute the batch files.

And for uninstall, the same approach - batch files are executed as pre-uninstall step and then the uninstall goes. I had to do something similar before. And I know it is a pain.

Wagner Silveira
+1  A: 

Why don;t you use the VS built-in installer? I've been using that for years.

The problem (and the reason why you might think it does not work) is that for a Windows service you have to add some custom actions in order for the service to register.

Have a look at this, and to to the To add a custom action to the setup project section:

http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx

gmagana
+1  A: 

Have your service accept an argument to register itself as a service:

MyService.exe /i

In your service, you check for this argument, and if present get the service to register itself:

ManagedInstallerClass.InstallHelper(args);

See my answer to this question for more details. This way, you can get the user to register the service themselves in a simple manner via the command line.

If this is still too complicated for your users, you could use Environment.UserInteractive to check whether or not the user double-clicked on the service. If so, install/uninstall the service. If not, start the service (this will be the route taken when the service starts via the services applet and at machine startup).

adrianbanks
A: 

Heres a really cool step-by-step guide of how to create a service installer using Visual Studio 2005. (is virtually identical in Visual Studio 2008).

http://aspalliance.com/1316_Working_with_Windows_Service_Using_Visual_Studio_2005.all

It helped me a lot :D

Rodrigo Garcia