Specify Windows Service Name on install with Setup Project

假如想象 提交于 2019-12-21 03:37:18

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/1070885/specify-windows-service-name-on-install-with-setup-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!