Installing a Windows Service using a Setup project
Posted by Clayton James 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.
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]
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.