Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify Windows Service Name on install with Setup Project

Objective: In support of a Windows Service that may have multiple instances on a single machine, use a Setup Project to create an MSI capable of:

  1. Receiving user input for Service Name
  2. Installing service
  3. Serializing Service Name from 1 (so that the proper name can be used in logging and uninstall)

My initial hope was to set Service Name in App.config (and then retrieve it during uninstall upon instantiation of the ServiceInstaller. This seems to have been naive, because it is not accessible during the install.

If MyInstaller extends Installer, it can call base.Install(); however, my attempts to write to app.config (within MyInstaller.Install() and after base.Install()) are inneffective.

So while the service can be installed with a custom Service Name, that name is not serialized and the installer is most displeased upon uninstall.

How should this be done?

like image 937
sympatric greg Avatar asked Jul 01 '09 19:07

sympatric greg


People also ask

How do I install a Windows service with a different name?

Open regedit.exe (Registry Editor). Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services and find the subkey with your service's name. Right-click the key you found in step #3, and select Rename. Enter the new name for the service.

How do I add project installer to Windows service?

In Solution Explorer, access Design view for the service for which you want to add an installation component. Click the background of the designer to select the service itself, rather than any of its contents. With the designer in focus, right-click, and then click Add Installer.

How do I setup a Windows project service?

Create Setup Project for Window Service Open a dialog box, go to left pane under Installed Templates > Other Project Types > Setup and Deployment > Visual Studio Installer and go to the right pane and select the project as a “Setup Project” and click on the OK button.


1 Answers

You can specify parameters to installer actions, so collect the service name, and pass it as a parameter to the action. Then, in the Installer class, you can override Install() and access it via base.Context.Parameters. That's how you get the value. Having obtained that value and used it, you put it in the stateSaver IDictionary parameter so that if you override Uninstall() you can find out what value was used on install.

like image 129
Neil Barnwell Avatar answered Oct 20 '22 14:10

Neil Barnwell