Get user input during installation using setup project and use it in installer

感情迁移 提交于 2019-12-11 10:48:00

问题


I have created an installer to install a windows service. Installer should ask user to name the service. Hence, I have created a custom UI in the installer with TextBox.

When user runs the setup.exe file, installation starts and the custom UI shows up. User adds the name for the windows service but how shall I take the ServiceName as user input during installation and set default service name into service name provided by user during installation in that custom UI.


回答1:


You need to follow these steps:

  1. Create a Windows Service project. It will create a service project containing Service1.cs.
  2. Open Service1.cs and right click and choose Add Installer. It will create a ProjectInstaller.cs.
  3. Add a new Setup Project. (If you don't have project template, download and install it from here for VS2013, VS2015 or VS2017)
  4. Add primary output of the service project to the setup project.
  5. Go to User Interface window and a new Dialog using TextBoxes (A) template after Installation Folder. (Set visible property of other textboxes than Edit1 to false.)
  6. Go to Custom Actions window and add a new custom action from primary output of the service project.
  7. In the Custom Action window, go to this node go to this node Custom ActionsInstallPrimary outputfrom WindowsService1 and in Properties window, set the value of CustomActionData to /SVCNAME=[EDITA1].
  8. Open ProjectInstaller.cs in your service project and override Install to set Name or DisplayName of the service:

    public override void Install(IDictionary stateSaver)
    {
        string value = Context.Parameters["SVCNAME"];
        this.serviceInstaller1.DisplayName = value;
        base.Install(stateSaver);
    }
    

Then build your projects and install the service.



来源:https://stackoverflow.com/questions/49783628/get-user-input-during-installation-using-setup-project-and-use-it-in-installer

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