Installing a Windows Service using a Setup project
Posted by CJ on June 5, 2006
I recently created a .NET Windows Service that needed to be deployed on a range of servers in various environments (dev, uat, train, prod). I needed an easy way (automated) to achieve this as our operations staff were completing the deployment and the service need to run under an account that I didn't know about.
InstallUtil.exe
To manually deploy a .NET Windows Service you can use InstallUtil.exe. However, this is a command utility and would require the VS2005 command prompt tool and InstallUtil.exe to be installed, the user would need to manually type command switches to configure the service.
Update to post
You can also use the command line tool "sc" to delete a service (as well as a whole bunch of other things, like set it to manual/auto, stop/start it, etc).
C:>sc delete
DESCRIPTION:
Deletes a service entry from the registry.
If the service is running, or another process has an
open handle to the service, the service is simply marked
for deletion.
USAGE:
sc delete [service name]
Setup Project
I won't go into detail as I found a great article that explains this. Simply put, the Setup project manages the installation of the Windows Service. It also manages a clean uninstall even when the service is running. This solution also allows me to use the User Interface Editor to add a Textboxes dialog so the person who is installing the service can input a Username and Password that the service account will run under. This uses the CustomActionEdit property to pass these values to the Windows Service installer which is another post in itself.
Mitko B said
Thank you!
Very pleasant article!
Ram said
I tried to install using a setup project, but it is not showing up in the service manager( where list of services are showed).Have you tried installing as mentioned in the article?
Tincy said
I am also facing the same trouble as Ram.
Created service is not showing up in the service manager ,Can anyone help?
Thanks
CJ said
You must install the service before it is displayed in Services.
To install the service from the Setup project you need to right-click the Setup project and select install (Step 5: Use a complied Setup project to install the Windows Service).
Once installed you will be able to view it at the following location:
Click Start, point to Control Panel, point to Administrative Tools, and then click Services.
Cheers
pradeep said
Hello CJ,
nice idea but i am unable to locate any thing helpful , even “Link” you mentioned is not available,
could u please put some helpsull stuff
Actually i want to install two service using one installer.
with Best Regards
Pradeep
Automobile said
Hello…
Looking for something else, but nice site. Have an excellent day….
kcherupa said
Please read this post which is an easy approach to install the windows services using setup project
http://cherupally.blogspot.com/2009/09/how-to-create-setup-project-to-install.html
Singh said
How can we add Re-Install support to a windows service, so that if the service is installed again, we don’t have to first uninstall and then install the service?